https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116491
Bug ID: 116491
Summary: GCC defines macro linux if -std is not set, and does
not define otherwise
Product: gcc
Version: 14.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: sergio_nsk at yahoo dot de
Target Milestone: ---
GCC 11+ default C++ standard is C++17. If the standard is not set explicitly
then GCC defines the macro `#define linux 1`. If the standard is set explicitly
then GCC does not define the macro.
int main() { static_assert(__cplusplus == 201703); }
#ifdef linux
#error linux
#endif
namespace linux {}
The code fails to compile with the command `g++ file.cc`: the significant my
code breakage error is
<source>:7:11: error: expected identifier before numeric constant
7 | namespace linux {}
| ^~~~~
<source>:7:11: error: expected unqualified-id before numeric constant
The code compiles well with the command `g++ -std=c++17 file.cc`
https://godbolt.org/z/7TnqTvozf
This bug is caught by cmake while requesting compiler features
`target_compile_features(target PUBLIC c_std_17)` that does not set
-std=gnu++17 if the default compiler version is C++17.