GnuCash
Contact   Instructions
Bug 798101 - Do not #undef __STRICT_ANSI__
Summary: Do not #undef __STRICT_ANSI__
Status: RESOLVED FIXED
Alias: None
Product: GnuCash
Classification: Unclassified
Component: General (show other bugs)
Version: git-master
Hardware: PC Linux
: Normal normal
Target Milestone: ---
Assignee: general
QA Contact: general
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-01-25 06:56 EST by Jonathan Wakely
Modified: 2021-01-30 20:41 EST (History)
3 users (show)

See Also:


Attachments
Patch to make the #undef conditional (427 bytes, patch)
2021-01-25 07:29 EST, Jonathan Wakely
no flags Details

Description Jonathan Wakely 2021-01-25 06:56:20 EST
As shown at https://github.com/Gnucash/gnucash/blob/267a7cb75d3b54cf359eb913c9f830b48307ae6a/libgnucash/backend/dbi/gnc-backend-dbi.cpp#L32-L36 the file does #undef __STRICT_ANSI__ unconditionally, but then only redefines it for Windows:
https://github.com/Gnucash/gnucash/blob/267a7cb75d3b54cf359eb913c9f830b48307ae6a/libgnucash/backend/dbi/gnc-backend-dbi.cpp#L88-L93

This means it is left undefined for other platforms. This causes undefined behaviour (even undefining the macro in the first place is undefined behaviour, so you should check if that workaround is really still needed for MinGW or if it can simply be removed).

In GCC 11 messing with that macro puts the C++ standard library into an inconsistent and broken state, and so there are checks in place to detect it. Due to the use of -Werror the warning about __STRICT_ANSI__ is an error, so gnucash 4.2 fails to compile in Fedora rawhide:

In file included from /usr/include/c++/11/cstdlib:41,
                 from /usr/include/c++/11/stdlib.h:36,
                 from /usr/include/glib-2.0/glib/gutils.h:433,
                 from /usr/include/glib-2.0/glib/gthread.h:34,
                 from /usr/include/glib-2.0/glib/gasyncqueue.h:32,
                 from /usr/include/glib-2.0/glib.h:32,
                 from /builddir/build/BUILD/gnucash-4.2/libgnucash/backend/dbi/gnc-backend-dbi.cpp:51:
/usr/include/c++/11/x86_64-redhat-linux/bits/c++config.h:2702:2: error: #warning "__STRICT_ANSI__ seems to have been undefined; this is not supported" [-Werror=cpp]
 2702 | #warning "__STRICT_ANSI__ seems to have been undefined; this is not supported"
      |  ^~~~~~~


See https://gcc.gnu.org/gcc-11/porting_to.html#strict-ansi for notes about the GCC 11 changes. The correct fix is documented there: instead of compiling in a strict mode and then trying to be unstrict, just stop using the wrong -std option in the first place.
Comment 1 Jonathan Wakely 2021-01-25 07:29:34 EST
Created attachment 373985 [details]
Patch to make the #undef conditional

Here's the workaround I'm using for Fedora.

This doesn't fix the problem for anybody using GCC 11 on Windows, so you'll still need to do it properly by using -std=gnu++17 instead of -std=c++17 in CMakeLists.txt
Comment 2 John Ralls 2021-01-30 20:41:17 EST
Indeed, none of that is needed any more.

Note You need to log in before you can comment on or make changes to this bug.