all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: maxim.cournoyer@gmail.com
To: 42392@debbugs.gnu.org
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	[thread overview]
Message-ID: <87imenk1ps.fsf@hurd.i-did-not-set--mail-host-address--so-tickle-me> (raw)

[-- Attachment #1: Type: text/plain, Size: 55 bytes --]

Hello,

The following C++ snippet file reproduces it:


[-- Attachment #2: reproducer --]
[-- Type: text/plain, Size: 233 bytes --]

// 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

[-- Attachment #3: Type: text/plain, Size: 13939 bytes --]


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	other threads:[~2020-07-16 13:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-16 13:51 maxim.cournoyer [this message]
2020-07-21 15:27 ` bug#42392: GCC includes ordering issue? g++: error: 'round' is not a member of 'std' Ludovic Courtès
2020-07-23  9:37   ` Ludovic Courtès
2020-07-24 12:24     ` Ludovic Courtès
2020-07-26  5:33   ` Maxim Cournoyer
2020-07-27 18:24     ` Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87imenk1ps.fsf@hurd.i-did-not-set--mail-host-address--so-tickle-me \
    --to=maxim.cournoyer@gmail.com \
    --cc=42392@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.