bug-guix
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#42392: GCC includes ordering issue? g++: error: 'round' is not a mem


From: maxim . cournoyer
Subject: bug#42392: GCC includes ordering issue? g++: error: 'round' is not a member of 'std'
Date: Thu, 16 Jul 2020 09:51:11 -0400

Hello,

The following C++ snippet file reproduces it:

// file: test.cpp

#include <cmath>
#include <iostream>


int main() {
    float x = 9.999;

    std::cout << "rounding value: " << x << " --> " << std::round(x);

    return 0;
}

// build with:
// g++ -o test.o -std=c++17 test.cpp
It affects only GCC 8 and newer, GCC 7 is fine.  The available "round"
seems to be the one originating from tgmath.h (implementation detail of
math.h AFAICT).

The std::round function is conditionally defined in the C++ standard
(since C++11) in the cmath header. It is supposed to also #undef the
global "round" macro, but it doesn't, or perhaps the ordering of the
includes is wrong and math.h gets included following cmath.

In cmath, macros such as 'round' are undefined based on some
conditions.  These conditions appear to be:

__cplusplus >= 201103L and _GLIBCXX_USE_C99_MATH_TR1 and not 
_GLIBCXX_NO_C99_ROUNDING_FUNCS

The following are some data points I've gathered from the following guix 
environment:

--8<---------------cut here---------------start------------->8---
guix environment --pure  gcc-toolchain@10 --ad-hoc coreutils findutils
strace the-silver-searcher
--8<---------------cut here---------------end--------------->8---


--8<---------------cut here---------------start------------->8---
echo $CPLUS_INCLUDE_PATH
/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/c++:/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include
--8<---------------cut here---------------end--------------->8---

The following lists the special #include_next directives, which tells
cpp (the C preprocessor) to look for the next file with that name in the
remaining of the its search path (as opposed to by starting the lookup
in the current search path).

--8<---------------cut here---------------start------------->8---
ag -f include_next $(realpath 
/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/*)
/gnu/store/jrzxs91zhpf6yr5fxisn3jjj7xai8zlk-gcc-10.1.0/include/c++/bits/std_abs.h
37:#define _GLIBCXX_INCLUDE_NEXT_C_HEADERS
38:#include_next <stdlib.h>
40:# include_next <math.h>
42:#undef _GLIBCXX_INCLUDE_NEXT_C_HEADERS

/gnu/store/jrzxs91zhpf6yr5fxisn3jjj7xai8zlk-gcc-10.1.0/include/c++/cmath
44:#define _GLIBCXX_INCLUDE_NEXT_C_HEADERS
45:#include_next <math.h>
46:#undef _GLIBCXX_INCLUDE_NEXT_C_HEADERS

/gnu/store/jrzxs91zhpf6yr5fxisn3jjj7xai8zlk-gcc-10.1.0/include/c++/complex.h
38:# include_next <complex.h>

/gnu/store/jrzxs91zhpf6yr5fxisn3jjj7xai8zlk-gcc-10.1.0/include/c++/cstdlib
74:#define _GLIBCXX_INCLUDE_NEXT_C_HEADERS
75:#include_next <stdlib.h>
76:#undef _GLIBCXX_INCLUDE_NEXT_C_HEADERS

/gnu/store/fa6wj5bxkj5ll1d7292a70knmyl7a0cr-glibc-2.31/include/limits.h
40:   #include's protect themselves, and in GCC 2 we may #include_next through
47:/* We don't have #include_next.
119:    We put this #include_next outside the double inclusion check because
124:# include_next <limits.h>

/gnu/store/jrzxs91zhpf6yr5fxisn3jjj7xai8zlk-gcc-10.1.0/include/c++/fenv.h
36:# include_next <fenv.h>

/gnu/store/jrzxs91zhpf6yr5fxisn3jjj7xai8zlk-gcc-10.1.0/include/c++/math.h
29:#if !defined __cplusplus || defined _GLIBCXX_INCLUDE_NEXT_C_HEADERS
30:# include_next <math.h>

/gnu/store/jrzxs91zhpf6yr5fxisn3jjj7xai8zlk-gcc-10.1.0/include/c++/stdlib.h
29:#if !defined __cplusplus || defined _GLIBCXX_INCLUDE_NEXT_C_HEADERS
30:# include_next <stdlib.h>

/gnu/store/jrzxs91zhpf6yr5fxisn3jjj7xai8zlk-gcc-10.1.0/include/c++/tgmath.h
35:#  include_next <tgmath.h>
--8<---------------cut here---------------end--------------->8---


Finally, the following lists the exact order in which g++/cpp have
opened them (I'm hoping that maps with the order it derived from its search
path/#include_next):

--8<---------------cut here---------------start------------->8---
strace -z -f -e trace=openat g++ -o test.o -std=c++14 test.cpp
[...]
[pid  8163] openat(AT_FDCWD, "test.cpp", O_RDONLY|O_NOCTTY) = 3
[pid  8163] openat(AT_FDCWD, "/tmp/ccEUTfto.s", O_WRONLY|O_CREAT|O_TRUNC, 0666) 
= 3
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/stdc-predef.h", 
O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD,
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/c++/cmath",
O_RDONLY|O_NOCTTY) = 4  # From gcc-10.1.0
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/jrzxs91zhpf6yr5fxisn3jjj7xai8zlk-gcc-10.1.0/include/c++/x86_64-unknown-linux-gnu/bits/c++config.h",
 O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/jrzxs91zhpf6yr5fxisn3jjj7xai8zlk-gcc-10.1.0/include/c++/x86_64-unknown-linux-gnu/bits/os_defines.h",
 O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/features.h", 
O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/sys/cdefs.h", 
O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/bits/wordsize.h", 
O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/bits/long-double.h",
 O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/gnu/stubs.h", 
O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/gnu/stubs-64.h", 
O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/jrzxs91zhpf6yr5fxisn3jjj7xai8zlk-gcc-10.1.0/include/c++/x86_64-unknown-linux-gnu/bits/cpu_defines.h",
 O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/c++/bits/cpp_type_traits.h",
 O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/c++/ext/type_traits.h",
 O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD,
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/math.h",
O_RDONLY|O_NOCTTY) = 4  # This one is from glibc-2.31
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/bits/libc-header-start.h",
 O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/bits/types.h", 
O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/bits/wordsize.h", 
O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/bits/timesize.h", 
O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/bits/typesizes.h", 
O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/bits/time64.h", 
O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/bits/math-vector.h",
 O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/bits/libm-simd-decl-stubs.h",
 O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/bits/floatn.h", 
O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/bits/floatn-common.h",
 O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/bits/long-double.h",
 O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/bits/flt-eval-method.h",
 O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/bits/fp-logb.h", 
O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/bits/fp-fast.h", 
O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/bits/mathcalls-helper-functions.h",
 O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/bits/mathcalls.h", 
O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/bits/mathcalls-helper-functions.h",
 O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/bits/mathcalls.h", 
O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/bits/mathcalls-helper-functions.h",
 O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/bits/mathcalls.h", 
O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/bits/mathcalls.h", 
O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/bits/mathcalls.h", 
O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/bits/mathcalls-helper-functions.h",
 O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/bits/mathcalls.h", 
O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/bits/mathcalls.h", 
O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/bits/mathcalls.h", 
O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/bits/mathcalls-narrow.h",
 O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/bits/mathcalls-narrow.h",
 O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/bits/mathcalls-narrow.h",
 O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/bits/mathcalls-narrow.h",
 O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/bits/mathcalls-narrow.h",
 O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/bits/mathcalls-narrow.h",
 O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/bits/mathcalls-narrow.h",
 O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/bits/mathcalls-narrow.h",
 O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/bits/mathcalls-narrow.h",
 O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/bits/mathcalls-narrow.h",
 O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/bits/mathcalls-narrow.h",
 O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/bits/mathcalls-narrow.h",
 O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/bits/mathcalls-narrow.h",
 O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/bits/iscanonical.h",
 O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/c++/bits/std_abs.h",
 O_RDONLY|O_NOCTTY) = 4
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/stdlib.h", 
O_RDONLY|O_NOCTTY) = 4

[...]

[pid  8163] openat(AT_FDCWD, "test.cpp", O_RDONLY) = 4
test.cpp: In function 'int main()':
test.cpp:10:61: error: 'round' is not a member of 'std'; did you mean 'round'?
   10 |     std::cout << "rounding value: " << x << " --> " << std::round(x);
      |                                                             ^~~~~
[pid  8163] openat(AT_FDCWD, 
"/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/bits/mathcalls.h", 
O_RDONLY) = 5
In file included from 
/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/features.h:465,
                 from 
/gnu/store/jrzxs91zhpf6yr5fxisn3jjj7xai8zlk-gcc-10.1.0/include/c++/x86_64-unknown-linux-gnu/bits/os_defines.h:39,
                 from 
/gnu/store/jrzxs91zhpf6yr5fxisn3jjj7xai8zlk-gcc-10.1.0/include/c++/x86_64-unknown-linux-gnu/bits/c++config.h:518,
                 from 
/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/c++/cmath:41,
                 from test.cpp:3:
/gnu/store/4rssdv43wikii23rghfjlr62z83x44r0-profile/include/bits/mathcalls.h:298:1:
 note: 'round' declared here
  298 | __MATHCALLX (round,, (_Mdouble_ __x), (__const__));
      | ^~~~~~~~~~~
[pid  8163] +++ exited with 1 +++
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=8163, si_uid=1000, 
si_status=1, si_utime=43, si_stime=8} ---
+++ exited with 1 +++
--8<---------------cut here---------------end--------------->8---

Perhaps the wrong math.h (the one from glibc) is being included? Indeed,
browsing its content, I can't see a definition for round, and all cmath
does is wrap the original definitions in the std namespace!

The possible math.h candidates are:

--8<---------------cut here---------------start------------->8---
find -L /gnu/store/dis9nlzbqy5j860gl1nxjijmcw9dsb6w-profile/include -name 
'*math.h' | xargs realpath
/gnu/store/jrzxs91zhpf6yr5fxisn3jjj7xai8zlk-gcc-10.1.0/include/c++/math.h
/gnu/store/jrzxs91zhpf6yr5fxisn3jjj7xai8zlk-gcc-10.1.0/include/c++/tgmath.h
/gnu/store/jrzxs91zhpf6yr5fxisn3jjj7xai8zlk-gcc-10.1.0/include/c++/tr1/math.h
/gnu/store/jrzxs91zhpf6yr5fxisn3jjj7xai8zlk-gcc-10.1.0/include/c++/tr1/tgmath.h
/gnu/store/fa6wj5bxkj5ll1d7292a70knmyl7a0cr-glibc-2.31/include/math.h
/gnu/store/fa6wj5bxkj5ll1d7292a70knmyl7a0cr-glibc-2.31/include/tgmath.h
--8<---------------cut here---------------end--------------->8---

The #include_next does what it's intended to do and pick math.h from
another search directory with a file of the same name, which it finds in
glibc.

I don't have any more ideas of things to look at at this point in time.

Maxim

reply via email to

[Prev in Thread] Current Thread [Next in Thread]