Bug 69767 - Clash with macros from sys/sysmacros.h
Summary: Clash with macros from sys/sysmacros.h
Status: RESOLVED MOVED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 6.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on: 11196
Blocks:
  Show dependency treegraph
 
Reported: 2016-02-11 11:09 UTC by Marek Polacek
Modified: 2025-03-21 12:46 UTC (History)
2 users (show)

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


Attachments

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...
Comment 5 Jonathan Wakely 2025-03-21 12:45:31 UTC
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.