The following should probably compile even with -std=c++11 or -std=c++14: #include <string> struct S { int major; int minor; S (int major = 1, int minor = 3); }; S::S(int major, int minor) : major (major), minor(minor) { } glibc's sys/sysmacros.h has these defines: /* Access the functions with their traditional names. */ #define major(dev) gnu_dev_major (dev) #define minor(dev) gnu_dev_minor (dev) #define makedev(maj, min) gnu_dev_makedev (maj, min)
GCC 5 behaves the same here. If I use #include <cstdlib> the the program won't compile even in C++03. Not 100 % sure this is a bug though...
Glibc includes sys/sysmacros.h conditionally based on: #ifdef __USE_MISC which is unfortunately always true for C++, because we define _GNU_SOURCE unconditionally (so this is a variation on PR 11196). I want to be able to stop defining that, probably for gcc7, but it's a big job.
I think glibc should simply stop defining those with __cplusplus?
And we can always fixinclude this...
Fixed by Glibc 2.28 * The macros 'major', 'minor', and 'makedev' are now only available from the header <sys/sysmacros.h>; not from <sys/types.h> or various other headers that happen to include <sys/types.h>. These macros are rarely used, not part of POSIX nor XSI, and their names frequently collide with user code; see https://sourceware.org/bugzilla/show_bug.cgi?id=19239 for further explanation. <sys/sysmacros.h> is a GNU extension. Portable programs that require these macros should first include <sys/types.h>, and then include <sys/sysmacros.h> if __GNU_LIBRARY__ is defined.