Bug 69767 - Clash with macros from sys/sysmacros.h
Summary: Clash with macros from sys/sysmacros.h
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 6.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2016-02-11 11:09 UTC by Marek Polacek
Modified: 2016-02-11 23:29 UTC (History)
2 users (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed: 2016-02-11 00:00:00


Note You need to log in before you can comment on or make changes to this bug.
Description Marek Polacek 2016-02-11 11:09:36 UTC
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)
Comment 1 Marek Polacek 2016-02-11 11:11:41 UTC
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...
Comment 2 Jonathan Wakely 2016-02-11 11:21:08 UTC
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.
Comment 3 Richard Biener 2016-02-11 11:51:00 UTC
I think glibc should simply stop defining those with __cplusplus?
Comment 4 Richard Biener 2016-02-11 11:51:16 UTC
And we can always fixinclude this...