Why is syntax error 'assert(false, "some text")' not discovered by Visual Studio?

Kohei Yoshida libreoffice at kohei.us
Wed Sep 19 00:27:48 UTC 2018

On Wed, 2018-09-19 at 01:29 +0200, Regina Henschel wrote:
> Hi all,
> I had the line
> assert(false, "Standard layer may not be deleted.");
> But Visual Studio 2017 does not detect the syntax error. Is there 
> something wrong with my environment?

No there is nothing "wrong" with your environment.  It just means that
you are building with a release (or a non-debug) configuration.  In
C/C++, assert() is not a real function but a compiler macro, which
replaces what's inside the parentheses () with something with a no-op
if you are building a release build before the compiler even gets a
chance to parse it.

You can either re-build yours with a debug configuration, or if you
just want to enable assert in a specific file only without re-building
the whole thing, then you can just insert

#undef NDEBUG

at the beginning of the file to trigger the assert calls in that file

Here is a longer version of this explanation:



Kohei Yoshida, LibreOffice Calc volunteer hacker

More information about the LibreOffice mailing list