c++ - G++ doesn't allow me to define a member function named "major" -
so, today coding unit tests, , g++ gave me unexpected warning regarding gnu c , 1 of member functions named major
. why can't have member function named major
without triggering g++?
this minimally viable test snippet:
// of these includes trigger warnings #include <random> #include <cstdlib> class my_class { public: void major() const; }; inline void my_class::major() const {} int main(void) { my_class my_obj; my_obj.major(); return 0; }
and output of compilation (using g++ --std=c++14 -o test-gcc-major test-gcc-major.cpp
):
[flisboac@sonic ~]$ uname -a && lsb_release -a && g++ -v && g++ --std=c++14 -o test-gcc-major test-gcc-major.cpp && ./test-gcc-major linux sonic 4.12.10-1-arch #1 smp preempt wed aug 30 12:18:42 cest 2017 x86_64 gnu/linux lsb version: 1.4 distributor id: arch description: arch linux release: rolling codename: n/a using built-in specs. collect_gcc=g++ collect_lto_wrapper=/usr/lib/gcc/x86_64-pc-linux-gnu/7.1.1/lto-wrapper target: x86_64-pc-linux-gnu configured with: /build/gcc-multilib/src/gcc/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --enable-libmpx --with-system-zlib --with-isl --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu --enable-gnu-indirect-function --enable-multilib --disable-werror --enable-checking=release --enable-default-pie --enable-default-ssp thread model: posix gcc version 7.1.1 20170630 (gcc) test-gcc-major.cpp:7:13: warning: in gnu c library, "major" defined <sys/sysmacros.h>. historical compatibility, defined <sys/types.h> well, plan remove soon. use "major", include <sys/sysmacros.h> directly. if did not intend use system-defined macro "major", should undefine after including <sys/types.h>. void major() const; ^~~~~~~~ test-gcc-major.cpp:10:13: warning: in gnu c library, "major" defined <sys/sysmacros.h>. historical compatibility, defined <sys/types.h> well, plan remove soon. use "major", include <sys/sysmacros.h> directly. if did not intend use system-defined macro "major", should undefine after including <sys/types.h>. inline void my_class::major() const {} ^~~~~~~~~~~~~~~~~~~~~~~~~~ test-gcc-major.cpp:14:13: warning: in gnu c library, "major" defined <sys/sysmacros.h>. historical compatibility, defined <sys/types.h> well, plan remove soon. use "major", include <sys/sysmacros.h> directly. if did not intend use system-defined macro "major", should undefine after including <sys/types.h>. my_obj.major();
the warning triggered every line referencing member function in way. also, can't undefine anything, because i'm implementing library, , burden should fall under final user.
so, know why warning being raised up? i'm not using c anywhere in code. i'm using <random>
, not c, per se (but may include "c" library, knows?).
in case, there way detect need , undefine major
@ compile-time (e.g. pre-processor voodoo)?
update: i'm using <random>
, not <cstdlib>
. found out <cstdlib>
also triggers warning.
it ok undefine macro, here backward compatibility only, removed, , shouldn't have been there in first place. there no way #undef
can possibly break or harm user code.
if users need macro and header included in same source file, let them sort out themselves. have anyway, whether include offending header or not , whether #undef
or not.
Comments
Post a Comment