With VS2017 (and a few MinGW based compilers that I know of and test with) this assert fails only when compiled in debug mode. Release mode and no assert failure.
Compile with VS2019 and no matter if compiled in Debug or Release mode and the assert fails.
In 2019 debug mode the Windows debug dialog pops up, the release fails "silently." No dialog box.
Seems like a rather serious bug to me. What you all think?
In 2019 debug mode the Windows debug dialog pops up, the release fails "silently." No dialog box.
What? If the assertion fails silently how can you tell it's failing? The program does nothing else.
An assertion being tested in release mode doesn't seem like such a big deal to me. Sure, it's a bug, but if your assertion failed the program probably had a bug anyway. I have at times written my own asserts that are always tested and throw catchable std::exceptions.
Running it from the IDE is not the same as running it normally. Compiling Debug vs Release has some effect on how the IDE behaves, but the IDE hooks the program either way.
C:\Users\Michael\Programming\cpp\cpp.com\foo
$ cl /EHsc /Ox /std:c++17 a.cpp /DNDEBUG=1
Microsoft (R) C/C++ Optimizing Compiler Version 19.20.27508.1 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
a.cpp
Microsoft (R) Incremental Linker Version 14.20.27508.1
Copyright (C) Microsoft Corporation. All rights reserved.
/out:a.exe
a.obj
C:\Users\Michael\Programming\cpp\cpp.com\foo
$ a
Was there an error?
[edit] Running without NDEBUG defined produces the correct assertion failure.
No, it works just like it is supposed to; I just proved it to you with my own VS 2019.
I think you are expecting behavior from the IDE that has nothing to do with the C++ standard.
Also, I make no pretense of any expertise with VS. I stick to the terminal precisely to avoid spending time on plumbing VS's depths.
[Edit] But mostly because I dont like the code editor
The IDE with 2019 doesn't apply NDEBUG when it is release mode, as it did with 2017. I checked the command line options in both and noticed the command line switch in 2019 was missing.
A command line switch you utilize when you compile via the command line.
I added a custom command switch to my project's settings for release mode (/D "NDEBUG") and now the assert doesn't fail. As it should per the standard.
[quote]I stick to the terminal precisely to avoid spending time on plumbing VS's depths./quote]
To each his own. I do use the IDE. And when something doesn't work as expected I mention it.
Hey, FG, I understand you are frustrated by the change, but you are making assertations contrary to fact. It is not part of any standard to predefine NDEBUG for any circumstance — it is totally up to the implementation how to handle that.
What is standard is that you can #define and #undef NDEBUG as many times as you want in any translation unit.
If it is that big of an issue (it would annoy me too), change VS’s global C++ project options and then you will never have to be annoyed by it again. Open a project (any project), then enable the Property Manager under the View menu.
In the Build Types in the Property Manager there are a number of different options (like “Release | x64”). The first item under each one is the global properties sheet (like “Microsoft.Cpp.x64.user”). Right-click and choose Properties and you will get the nice dialog to modify the global project options for a x64 C++ Release build.
Add the NDEBUG to your list of defines and save.
(You could also edit the XML directly, but it is easier from the IDE.)