I published on YouTube a video discussing how I solved the Day 1 puzzle of Advent of Code 2026 using C++.
Enjoy!
I published on YouTube a video discussing how I solved the Day 1 puzzle of Advent of Code 2026 using C++.
Enjoy!
An example of silent sneaky bug, with MSVC giving a *false* sense of security with [[nodiscard]].
Consider the following C++ code snippet:
static [[nodiscard]] int GetSomething()
{
return 64;
}
If you invoke this function like this:
int main()
{
GetSomething();
}
the code compiles successfully with MSVC!
Even at warning level 4 (/W4, which I use on almost all my VC++ projects)!
Why am I upset? Because in the above code I do discard the return value of GetSomething(), and even with the [[nodiscard]] attribute applied to the function, and compiling at /W4, the MSVC C++ compiler does not complain. I do want the compiler to complain in this case! 🙂
Dear MSVC C++ compiler, speak up! Say something like: “Hey, you discarded the return value of GetSomething(), which is marked with the [[nodiscard]] attribute. Please fix your code.”
The interesting thing is that, if you change the position of the [[nodiscard]] attribute, putting it before “static”, you get the expected warning:
// Was:
// static [[nodiscard]] int GetSomething()
//
// Now put [[nodiscard]] at the beginning of the line,
// before "static":
//
[[nodiscard]] static int GetSomething()
{
return 64;
}
Now the C++ compiler complains when trying to compile the above code snippet inside main(), with: “warning C4834: discarding return value of function with [[nodiscard]] attribute”. Great!
The problem is that, a wrong behavior is being silently accepted, even at warning level 4! The MSVC compiler gave me a false sense of security!
I compiled the above code in C++20 mode at /W4 with Visual Studio 2022.
Interestingly, both Clang and GCC refuse to compile the code with [[nodiscard]] in the wrong position, while unfortunately MSVC does silently swallow that.
For example, Clang emits the following clear error message:
![Clang correctly emits an error when [[nodiscard]] is written in the wrong position.](https://i0.wp.com/giodicanio.com/wp-content/uploads/2026/10/cpp_nodiscard_clang_error.png?resize=828%2C192&ssl=1)
On Windows, my favorite IDE for C++ (and some C#) programming is Visual Studio, and I use the Microsoft Visual C++ compiler (MSVC) to compile my C++ code. I hope that this silent sneaky compiler bug is fixed ASAP.
EDIT (November 28th, 2026): If you come reading this blog post from the future, this bug was fixed in the current MSVC C++ compiler that ships with Visual Studio 2026, i.e.: Microsoft C++ (MSVC) Build Tools version 14.52. Considering that Visual Studio 2022 is still in LTSC “long-term” support, I would have liked this bug to be fixed in the MSVC that ships with VS 2022, too.
P.S. At least by default, the VS 2022 IDE seems nicer to me than VS 2026; for example: instead of the solid nice recognizable icons representing folders in Solution Explorer in VS 2022, VS 2026 uses ugly outlines of folders, which are harder to recognize. Microsoft: please stop regressing IDE UIs and bring back a VS 2022-style Blue Theme for VS 2026. Again.
There is a myth according to which every new C++ version is backward compatible with the older versions. While there is a common general trend to try and keep backward compatibility across different C++ versions, that’s not always the case.
A “recent” example is provided by C++20’s u8 and char8_t.
Consider the following C++ code snippet:
// This function takes a UTF-8 string as input,
// and does something with it.
void DoSomething(const char* utf8Text);
...
int main()
{
// A UTF-8 string literal
auto s = u8"Connie plus some UTF-8 stuff...";
DoSomething(s);
}
The above code compiles successfully in C++17 mode.
Now you want to be cool and update your language standard to C++20, because, you know, we are in 2026 😉
Well, surprise, surprise…the same code will not compile in C++20 mode!

The MSVC compiler complains with the following error message:
‘void DoSomething(const char *)’: cannot convert argument 1 from ‘const char8_t *’ to ‘const char *’
The reason for that is that until C++20 a u8 string literal was interpreted as a const char array; on the other hand, C++20 did introduce a breaking change, and the same u8 string literal is now a const char8_t array in the new standard!
| u8″…” Syntax | Type | Encoding |
| Until C++20 (C++11, 14, 17) | const char[N] | UTF-8 |
| Since C++20 | const char8_t[N] | UTF-8 |
The DoSomething function expects a char-based string, not a char8_t-based string, and so the C++ compiler complains in C++20 mode.
Of course, this was a simple example to illustrate the nature of the problem. But suppose that you are working with large libraries and existing codebases that used to compile just fine in previous C++ standards (e.g. C++17), and now the same code break all of a sudden when you switch to C++20 mode!
To mitigate the problem, an option could be to avoid the use of the u8 prefix when possible.
For example, this is what Google’s C++ Style Guide currently suggests:
When possible, avoid the
u8prefix. It has significantly different semantics starting in C++20 than in C++17, producing arrays ofchar8_trather thanchar, and will change again in C++23.
What C++ version should you target in your codebase? There’s no easy answer, except maybe “it depends”…
This is an interesting question, with not an easy answer.
I would say that the correct answer is: “It depends.”
Modern C++ started with C++11. I think C++11 is the most impactful version of C++ to date, as it introduced very important and convenient features like: range-for loops, lambdas, move semantics, standard smart pointers like std::unique_ptr and std::shared_ptr, etc.
C++14 was kind of a small improvement for things that didn’t make it into C++11. For example, C++11 had std::make_shared for std::shared_ptr, but it clearly lacked the corresponding std::make_unique for std::unique_ptr. Well, std::make_unique (and other small features, like supporting auto in lambda parameters) were added in C++14.
Then it came C++17. Again, no big new features here, at least not at the C++11 impact level, but some convenient stuff, like: attributes (e.g. [[nodiscard]], [[fallthrough]], or [[maybe_unused]]); static_assert with no messages (a.k.a. terse static_assert); structured bindings, which come in handy in some cases like when iterating through containers like std::map; new standard library components that can be useful, like std::optional, std::variant, etc.
Some library features that were previously deprecated were definitively removed in C++17; so that could break some existing legacy C++ code that previously compiled just fine in your projects.
And this brings an important point when picking the C++ version for your codebase: Does using C++ version X > Y break existing code? Is it compatible with older legacy libraries that you don’t want to or cannot upgrade or fix? Does it break some binary compatibility interface (ABI)1? Is it supported by your toolchain(s)?
For example, if you want to target Windows XP with Microsoft Visual C++ compiler, the latest toolset that has Windows XP support is v141_xp, which is a toolset from Visual Studio 20172, having full C++14 support, and partial C++17 support (for example: you can use C++17 features like terse static_assert, std::optional, and std::variant; but not other features like std::shared_mutex).3
In general, I would say that these days targeting C++17 is fine, and if your toolset supports C++20, and if it doesn’t break any existing library or legacy component you depend on (and you don’t want to/are unable to fix), then C++20 can be a good choice, too.
Keep in mind that today in 2026 (August 18th, 2026), Google’s C++ Style Guide still targets C++204, and LLVM C++17.


Note also that targeting a given C++ version, like C++20, does not mean that you have to use all the features available in that language version!
For example, talking about the C++20 adoption by Google’s C++ Style Guide, it’s worth noting that, the main “Big Three Features” of C++20, i.e. concepts, modules, and coroutines, are used sparingly, or not used at all!
For example, on concepts:
Use concepts sparingly.
And on coroutines:
Use only coroutine libraries that have been approved for project-wide use by your project leads. Do not roll your own promise or awaitable types.
Moreover, on C++20 modules:
Do not use C++20 Modules.
Remember that, at the end of the day, the key is to write code that is clear, easy to read, understand and maintain, and not some mess of esotheric advanced features that make it impossible or very hard to understand what’s going on, or unstable features not well supported by the available toolsets.
Another example showing how AI output should be carefully reviewed, and not accepted passively.
I was “discussing” with Claude about using #define guards vs. #pragma once for C++ header files. At some point, Claude wrote that:
If your library is only ever going to target modern mainstream compilers (which, realistically, is true for almost everyone today), plain
#pragma onceis fine and is what most modern C++ style guides (including Google’s and LLVM’s) now recommend by default.
I did remember that, last time I checked, Google’s C++ Style Guide required #define guards (not #pragma once) for header files. That is still true as of today (August 18th, 2026); quoting Google’s C++ Style Guide on this point:
All header files should have
#defineguards to prevent multiple inclusion. The format of the symbol name should be<PROJECT>_<PATH>_<FILE>_H_.
So I made my point to Claude, and it replied apologizing for its error:
You’re right, and I apologize for the error. Looking at the actual page, Google’s C++ Style Guide explicitly requires
#defineguards, not#pragma once
This is another example showing how AI output cannot be 100% trusted, and should always be carefully reviewed.


I briefly asked another AI (Gemini) about AI hallucinations (like the previous example with Claude), and it interestingly pointed out that:
AI models predict the next most likely word based on patterns in data.
They do not have real-world awareness or a true concept of “truth.”
That is something to keep in mind when dealing with AI.

This is a concrete real-world example showing how AI-generated results should not be 100% completely trusted.
Recently I asked Claude to review the code of my WinReg C++ library (which is a C++ high-level wrapper around the low-level C-interface Windows Registry API).
As a result of its analysis, Claude reported that there were zero-length bugs in my code, in particular Claude stated that zero-length REG_SZ/REG_EXPAND_SZ values crash the GetStringValue, GetExpandStringValue, TryGetStringValue and TryGetExpandStringValue methods of the RegKey class.
In particular, Claude noted that I correctly guarded against dataSize == 0 in the binary-returning getters (like RegKey::GetBinaryValue), but the string getters do not have such guard; they unconditionally do:
result.resize((dataSize / sizeof(wchar_t)) - 1);
Claude specified that REG_SZ and REG_EXPAND_SZ values can be legitimately stored with cbData == 0 (zero bytes, no NUL at all; different from an empty string made by a single NUL ‘\0’).
If you substitute zero for the dataSize variable in the above statement, you end up with:
result.resize(SIZE_MAX);
which would throw a std::length_error exception.

Claude proposed to fix the above code using the same edge-case check logic I had already implemented in the binary getters to guard against the zero-length case:
if (dataSize == 0)
{
result.clear();
}
else
{
result.resize((dataSize / sizeof(wchar_t)) - 1);
}
My WinReg library is quite battle-tested, and there were bugs related to some edge cases that I had already fixed, so I was curious, and tried writing a zero-length string value in the registry, and read it back with my existing code. And I noted that (at least in Windows 11 where I tested my code) the dataSize == 0 condition was not hit at run-time.
That is because in my C++ code I invoke the RegGetValue(W) API, which by contract guarantees to return a NUL-terminated string, even if the string stored in the registry doesn’t have a NUL-terminator. (This is not the case for older APIs like RegQueryValueEx.)
I replied to Claude pointing that out, and Claude corrected itself:


You’re right, and thanks for the pushback — I should have accounted for
RegGetValueW‘s null-termination guarantee before flagging that as a bug.
Those AI tools can be very powerful, but the key takeway here is that we should not forget that they are just tools, and we should not trust AI-generated output and code 100%, because bugs and wrong assumptions can be hidden in that AI code, too.
Discussing several options, starting from the good old C-style void* pointer.
An interesting question you may ask in C++ is: “How would you declare a function that takes a blob of memory as input?”
For example, think of a function that hashes some input data (using SHA-256, or whatever hash algorithm), or a function that takes some binary data and writes that to disk.
Coming from my C background, an option that came to mind would certainly be:
void DoSomething(const void* p, size_t numBytes)
You simply pass a const void* pointer to the beginning of the input memory block, and the total size of the memory block, expressed in bytes.
Then, some C++ programmer could start complaining: “Hey, why do you use the unsafe old C-style void* pointer? Use some safe explicit type like uint8_t, which clearly represents an 8-bit byte!”.
So, they propose to “step up” to the following prototype:
void DoSomething(const uint8_t* p, size_t numBytes)
Now, suppose that you want to pass to this function a custom structure, like this:
struct MyCustomData {
...
};
MyCustomData data;
With the original void* version, you can invoke the function simply and clearly like this:
DoSomething(&data, sizeof(data));
The code is very clear and straightforward: you pass a pointer to the custom data structure, and its size in bytes. That’s it. Simple and clear.
On the other hand, with the “safe and modern” uint8_t prototype, the function call gets more complicated, as you need to add a type cast:
// void DoSomething(const uint8_t* p, size_t numBytes)
//
// DoSomething(&data, sizeof(data));
//
// This gives a compiler error when the function expects
// a const uint8_t* instead of const void*, something like:
//
// Error: cannot convert 'MyCustomData*' to 'const uint8_t*'
//
// You need an explicit cast in this case!
DoSomething(
reinterpret_cast<const uint8_t*>(&data),
sizeof(data)
);
Why should people complexify and uglify their C++ code with the uint8_t pointer (or std::byte), when void* works just fine??
Moreover, someone could even say: “Hey, in modern C++20, we have std::span! Use it!”
Well, congratulations for rising the complexity and noise of the code even further!
In fact, std::span is a class template, and somebody would suggest to make the function that processes the generic memory blob a function template! Really? Something like this??
template <typename T>
void DoSomething(std::span<T> data)
Or maybe something even more complicated, like this?
template <typename T, std::size_t N>
void DoSomething(std::span<T, N> data)
// Or this?
template <typename T, std::size_t N>
void DoSomething(std::span<const T, N> data)
Wow. With std::span the complexity-meter bumps in the red zone and goes even higher!
Someone may suggest something like a std::span<const uint8_t>? But that’s still more complex than the initial void* signature.
Do you want a pointer to a generic memory blob? C++ has already if from C: it’s called void*! Use it and enjoy.
I really dislike this attitude of some “modern” C++ programmers, that make choices that have the effect of making the code more complex, uglier and harder to write and understand.
It seems that some people are really losing the taste for good readable code.
Some good old habit from C can still be positively used in C++, like the void* pointer and the size parameters.
BTW: As a nice addition, if you use SAL annotations, the function could be decorated a bit to help code analyzers detecting memory bugs:
void DoSomething(
_In_reads_bytes_(numBytes) const void * p,
_In_ size_t numBytes
);
The _In_reads_bytes_ annotation applied to the pointer parameter explicitly states that the pointer points to input read-only memory (_In_reads_), and the size of this input buffer expressed in bytes (_bytes_) is represented by the numBytes parameter.
In this way, we still keep the clarity and simplicity of the function invocation:
DoSomething(&data, sizeof(data));
while also adding pieces of information that are helpful to spot memory bugs with code analyzers and other tools.
If you want to learn more about SAL annotations, you can start reading this MSDN documentation: Using SAL Annotations to Reduce C/C++ Code Defects.
The process of submitting article suggestions to IsoCpp.org can be kind of “frustrating”, with inconsistencies in acceptance timing and a lack of communication. Making suggestions requires some effort, yet the outcomes feel random. I propose some improvements.
I have suggested several articles to the IsoCpp.org Web site. Some article suggestions were published just a few hours after sending them; others the next day or two, others after a week or two, while other suggestions seemed like lost by anonymous persons in a “black hole”. Who processed those suggestions? Why were those rejected?
This process seems kind of random and unprofessional, and not respectful for the time we put in suggesting articles.
In fact, for suggesting an article, it’s not sufficient to copy-and-paste a link to the content and just click a “Suggest” button. You have to prepare a little document, following a pattern and some editorial guides made available from the IsoCpp Web site. It does take some time.
Then, you click the button to make the suggestion… and it’s like a random coin toss! Will the suggestion be accepted? Will the suggestion be discarded? When? Why? By whom?
The process is clearly broken, and should be fixed, out of respect for the time of the people who made a suggestion, and for what should be a quality Web site that lists links to relevant content.
A possible fix to the process could be like this:
Once you make a suggestion, an email is sent to you, saying that the IsoCpp editorial team has received the suggestion, and will reply in a maximum given period of time: one week, two weeks, whatever. But do give a time limit, and don’t just disappear! I think a 15-day time limit for a reply would be acceptable.
Then, do send a reply to the person suggesting the article, be it positive or negative. But do send a reply! If the suggestion is accepted, say thank you and give a link to the Web page containing the suggestion.
On the other hand, if the suggestion is not accepted, say thank you again, and do give a reason for the refusal. And also give the person suggesting the article an option to further discuss that via email with the editor who refused the suggestion, with the option to discuss that with other editors, too.
Moreover, once a person has a certain number of approved suggestions, let the system automatically approve their suggestions by default. This “privilege level” could be revoked if a certain number of unworthy suggestions or suggestions not relevant for the IsoCpp topics are made.
Manually editing the tasks.json to add the desired C++ compiler option.
So, after the previous discussion on that confusing UI design choice, how can you set the C++ language standard version for building your C++ code in VS Code with the MS C/C++ Extension?
One option is to open the tasks.json file, and edit it to add the desired compiler option. In particular, to enable C++20 compilation mode, the option for the MSVC compiler is /std:c++20. So, add this option as a string “/std:c++20” in the args property array in tasks.json:

I still think that this modification to tasks.json should have been automatically done by the C/C++ Configurations UI, once the C++20 language standard version is set in there.
In VS Code, selecting the C++ language standard is not as intuitive as one would expect.
I have been using Visual Studio for C++ development since it was still called Visual C++ (and was a 100% C++-focused IDE), starting from version 4 (maybe 4.2) on Windows 95. I loved VC++ 6. Even today, Microsoft Visual Studio is still my first choice for C++ development on Windows.
In addition to that, I wanted to use VS Code for C++ development for some course work. Why choosing VS Code? Well, in addition to being free to use (as is the Visual Studio Community Edition), another important point of VS Code in that teaching context is its cross-platform feature: in fact, it’s available not only for Windows, but also for Linux and Mac, and students using those platforms could easily follow along.
I had VS Code and the MS C/C++ extension already installed on one of my PCs. I wrote some C++ demo code that used some C++20 features. I tried to build that code, and I got some error messages, telling me that I was using features that required at least C++20. Fine, I thought: Maybe the default C++ standard is set to something pre-C++20 (for example, VS 2019 defaults to C++14).
So, I pressed Ctrl+Shift+P, selected C/C++ Edit Configurations (UI), and in the C/C++ Configurations page, selected c++20 for the C++ standard.
Then I pressed F5 to start a debugging session, preceded by a build process, and saw that the build process failed.
I took a look at the error message in the terminal window, and to my surprise the error messages were telling me that some libraries (like <span>) were available only with C++20 or later. But I had just selected the C++20 standard a few minutes ago!
So, I double-checked, pressing Ctrl+Shift+P and selecting C/C++ Edit Configurations (UI), and in the C/C++ Configurations, the selected C++ standard was c++20, as expected.

I also took a look at the c_cpp_properties.json, and found that the “cppStandard” property was properly set to “c++20”, as well.

Despite these confirmations in the UI, I noted that in the terminal window, on the command line used to build the C++ source code, the option to set the C++20 compilation mode was not passed to the C++ compiler!

So, basically, the UI was telling me that the C++20 mode was enabled. But the C++ compiler was invoked in a way that did not reflect that, as the flag enabling C++20 was not specified on the command line!
I also tried to close and reopen VS Code, double-checked things one more time, but the results were always the same: C++20 was set in the C/C++ Configurations UI and in the c_cpp_properties.json file, but compilation failed due to the C++20 option not specified on the command line when invoking the C++ compiler.
I thought that this was a bug, and opened an issue on the MS C/C++ Extension GitHub page.
After some time, to my surprise, I noted that the issue was closed as “by design”! Seriously? I mean, what kind of good reasonable intuitive design is the one in which the UI tells you that you have selected a given C++ language standard, but the command line doesn’t compile your code according to that??
This is the comment associated to the closing of the issue:
This is “by design”. The settings in c_cpp_properties.json do not affect the build. You need to set the flags in your tasks.json or other source of build info (CMakeLists.txt etc.).
So, am I supposed to manually set the C++20 flag in the tasks.json, despite having already set it in the C/C++ Configurations UI? Well, I do think that is either a bug, or a bad and confusing design choice. If I set the C++20 option in the UI, that should be automatically reflected on the command line, as well. If a modification is required to tasks.json to enable C++20, that should have been the job of the UI, in which I had already selected the C++20 standard!
Compare that to the sane intuitive behavior of Visual Studio, in which you can simply set the C++ standard option in the UI, and the IDE will invoke the C++ compiler with the proper flags, reflecting that.
