clang++ in a {clang-toolchain + gcc-toolchain} environment

  • Open
  • quality assurance status badge
Details
2 participants
  • Emmanuel Agullo
  • Ludovic Courtès
Owner
unassigned
Submitted by
Emmanuel Agullo
Severity
normal
E
E
Emmanuel Agullo wrote on 24 Aug 2020 15:43
(address . bug-guix@gnu.org)
109069324.10892414.1598276637610.JavaMail.zimbra@inria.fr
Hello,

A typical "hello world" C++ fails in an environment with both
`gcc-toolchain' and `clang-toolchain', apperently due to the setup of
the `CPLUS_INCLUDE_PATH' environment variable (used because of the
`#include <iostream>' instruction), when compiling with `clang++'.

I do not know if this is a bug or the expected behaviour. Obviously one
is not likely to explicitly load an environment with both `gcc-toolchain'
and `clang-toolchain' but migth do so implictly (and possibly not being
aware of it) for instance having `gcc-toolchain' globally installed and
at some point loading `clang-toolchain' in an environment.

Note that it is not critical at all in practice in my case, and I do
not know whether it it is desirable to fix it in some way, or, maybe
mention the incompatibility somewhere
already done so – in which case I am sorry for the noise.

Please find below:
1. a simplified C++ "hello world" hello.cpp program
2. an expected g++ behaviour in a `gcc-toolchain' environment
3. an expected clang++ behaviour in a `clang-toolchain' environment
4. an environment with both `gcc-toolchain' & `clang-toolchain'
- 4.1. with an expected behaviour using `g++'
- 4.2. with an (expected or not?) error using `clang++'
- 4.3. a (non desirable) fix of the `CPLUS_INCLUDE_PATH' (removing
`/gnu/store/…/include/c++')
5. the employed channels if it may help

Thanks much for the continous development and support, and once
again sorry for the possible noise if this is a known expected
behaviour.

With best regards,

Emmanuel


1 simplified (no newline) C++ "hello world" hello.cpp program
?????????????????????????????????????????????????????????????

?????
? #include <iostream>
?
? int main() {
? std::cout << "Hello World!";
? return 0;
? }
?????


2 `gcc-toolchain' environment
?????????????????????????????

?????
? guix environment -C --ad-hoc gcc-toolchain coreutils grep
? env | grep CPLUS_INCLUDE_PATH
? g++ hello.cpp
? ./a.out
?????

????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
CPLUS_INCLUDE_PATH=/gnu/store/gsylxn8q06w6y7622nw159f3q1vvcx2i-profile/include/c++:/gnu/store/gsylxn8q06w6y7622nw159f3q1vvcx2i-profile/include
Hello World!
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????


3 `clang-toolchain' environment
???????????????????????????????

?????
? guix environment -C --ad-hoc clang-toolchain coreutils grep
? env | grep CPLUS_INCLUDE_PATH
? clang++ hello.cpp
? ./a.out
?????

????????????????????????????????????????????????????????????????????????????????????????
CPLUS_INCLUDE_PATH=/gnu/store/8qlafmilvc0g1yv8lmilpjmps3p4nrmq-profile/include
Hello World!
????????????????????????????????????????????????????????????????????????????????????????


4 environment with both `gcc-toolchain' & `clang-toolchain'
???????????????????????????????????????????????????????????

4.1 compilation with `g++'
??????????????????????????

`g++' in an environment with both gcc and clang toolchains is fine:
?????
? guix environment -C --ad-hoc gcc-toolchain clang-toolchain coreutils grep
? env | grep CPLUS_INCLUDE_PATH
? g++ hello.cpp
? ./a.out
?????

????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
CPLUS_INCLUDE_PATH=/gnu/store/3ka3a9wgx5sk6ac84nldx7ldpxppn29z-profile/include/c++:/gnu/store/3ka3a9wgx5sk6ac84nldx7ldpxppn29z-profile/include
Hello World!
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????


4.2 compilation with `clang++' (FAIL)
?????????????????????????????????????

But `clang++' in the same environment (with both gcc and clang
toolchains) breaks, raising the following error:
?????
? guix environment -C --ad-hoc gcc-toolchain clang-toolchain coreutils grep
? clang++ hello.cpp
?????

Error obtained during the `clang++ hello.cpp' step:
?????
? In file included from hello.cpp:1:
? In file included from /gnu/store/3ka3a9wgx5sk6ac84nldx7ldpxppn29z-profile/include/c++/iostream:39:
? In file included from /gnu/store/3ka3a9wgx5sk6ac84nldx7ldpxppn29z-profile/include/c++/ostream:38:
? In file included from /gnu/store/3ka3a9wgx5sk6ac84nldx7ldpxppn29z-profile/include/c++/ios:39:
? /gnu/store/3ka3a9wgx5sk6ac84nldx7ldpxppn29z-profile/include/c++/exception:105:3: error: unknown type name '_GLIBCXX17_DEPRECATED'
? _GLIBCXX17_DEPRECATED
? ^
? In file included from hello.cpp:1:
? In file included from /gnu/store/3ka3a9wgx5sk6ac84nldx7ldpxppn29z-profile/include/c++/iostream:39:
? In file included from /gnu/store/3ka3a9wgx5sk6ac84nldx7ldpxppn29z-profile/include/c++/ostream:38:
? In file included from /gnu/store/3ka3a9wgx5sk6ac84nldx7ldpxppn29z-profile/include/c++/ios:39:
? In file included from /gnu/store/3ka3a9wgx5sk6ac84nldx7ldpxppn29z-profile/include/c++/exception:147:
? In file included from /gnu/store/3ka3a9wgx5sk6ac84nldx7ldpxppn29z-profile/include/c++/bits/exception_ptr.h:40:
? /gnu/store/3ka3a9wgx5sk6ac84nldx7ldpxppn29z-profile/include/c++/new:126:1: error: unknown type name '_GLIBCXX_NODISCARD'
? _GLIBCXX_NODISCARD void* operator new(std::size_t) _GLIBCXX_THROW (std::bad_alloc)
? ^
? /gnu/store/3ka3a9wgx5sk6ac84nldx7ldpxppn29z-profile/include/c++/new:128:1: error: unknown type name '_GLIBCXX_NODISCARD'
? _GLIBCXX_NODISCARD void* operator new[](std::size_t) _GLIBCXX_THROW (std::bad_alloc)
? ^
? /gnu/store/3ka3a9wgx5sk6ac84nldx7ldpxppn29z-profile/include/c++/new:140:1: error: unknown type name '_GLIBCXX_NODISCARD'
? _GLIBCXX_NODISCARD void* operator new(std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
? ^
? /gnu/store/3ka3a9wgx5sk6ac84nldx7ldpxppn29z-profile/include/c++/new:142:1: error: unknown type name '_GLIBCXX_NODISCARD'
? _GLIBCXX_NODISCARD void* operator new[](std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT
? ^
? /gnu/store/3ka3a9wgx5sk6ac84nldx7ldpxppn29z-profile/include/c++/new:174:1: error: unknown type name '_GLIBCXX_NODISCARD'
? _GLIBCXX_NODISCARD inline void* operator new(std::size_t, void* __p) _GLIBCXX_USE_NOEXCEPT
? ^
? /gnu/store/3ka3a9wgx5sk6ac84nldx7ldpxppn29z-profile/include/c++/new:175:10: error: cannot initialize return object of type 'int *' with an lvalue of type 'void *'
? { return __p; }
? ^~~
? /gnu/store/3ka3a9wgx5sk6ac84nldx7ldpxppn29z-profile/include/c++/new:176:1: error: unknown type name '_GLIBCXX_NODISCARD'
? _GLIBCXX_NODISCARD inline void* operator new[](std::size_t, void* __p) _GLIBCXX_USE_NOEXCEPT
? ^
? /gnu/store/3ka3a9wgx5sk6ac84nldx7ldpxppn29z-profile/include/c++/new:177:10: error: cannot initialize return object of type 'int *' with an lvalue of type 'void *'
? { return __p; }
? ^~~
? In file included from hello.cpp:1:
? In file included from /gnu/store/3ka3a9wgx5sk6ac84nldx7ldpxppn29z-profile/include/c++/iostream:39:
? In file included from /gnu/store/3ka3a9wgx5sk6ac84nldx7ldpxppn29z-profile/include/c++/ostream:38:
? In file included from /gnu/store/3ka3a9wgx5sk6ac84nldx7ldpxppn29z-profile/include/c++/ios:39:
? In file included from /gnu/store/3ka3a9wgx5sk6ac84nldx7ldpxppn29z-profile/include/c++/exception:148:
? In file included from /gnu/store/3ka3a9wgx5sk6ac84nldx7ldpxppn29z-profile/include/c++/bits/nested_exception.h:40:
? In file included from /gnu/store/3ka3a9wgx5sk6ac84nldx7ldpxppn29z-profile/include/c++/bits/move.h:57:
? /gnu/store/3ka3a9wgx5sk6ac84nldx7ldpxppn29z-profile/include/c++/type_traits:696:27: error: expected unqualified-id
? _GLIBCXX20_DEPRECATED("use is_standard_layout && is_trivial instead")
? ^
? /gnu/store/3ka3a9wgx5sk6ac84nldx7ldpxppn29z-profile/include/c++/type_traits:696:27: error: expected ')'
? /gnu/store/3ka3a9wgx5sk6ac84nldx7ldpxppn29z-profile/include/c++/type_traits:696:26: note: to match this '('
? _GLIBCXX20_DEPRECATED("use is_standard_layout && is_trivial instead")
? ^
? /gnu/store/3ka3a9wgx5sk6ac84nldx7ldpxppn29z-profile/include/c++/type_traits:2648:5: error: unknown type name '_GLIBCXX20_CONSTEXPR'
? _GLIBCXX20_CONSTEXPR
? ^
? /gnu/store/3ka3a9wgx5sk6ac84nldx7ldpxppn29z-profile/include/c++/type_traits:2650:5: error: no variable template matches partial specialization
? _Require<__not_<__is_tuple_like<_Tp>>,
? ^
? /gnu/store/3ka3a9wgx5sk6ac84nldx7ldpxppn29z-profile/include/c++/type_traits:2652:31: error: expected ';' at end of declaration
? is_move_assignable<_Tp>>
? ^
? /gnu/store/3ka3a9wgx5sk6ac84nldx7ldpxppn29z-profile/include/c++/type_traits:2653:10: error: unknown type name '_Tp'
? swap(_Tp&, _Tp&)
? ^
? /gnu/store/3ka3a9wgx5sk6ac84nldx7ldpxppn29z-profile/include/c++/type_traits:2653:16: error: unknown type name '_Tp'
? swap(_Tp&, _Tp&)
? ^
? /gnu/store/3ka3a9wgx5sk6ac84nldx7ldpxppn29z-profile/include/c++/type_traits:2654:51: error: use of undeclared identifier '_Tp'
? noexcept(__and_<is_nothrow_move_constructible<_Tp>,
? ^
? /gnu/store/3ka3a9wgx5sk6ac84nldx7ldpxppn29z-profile/include/c++/type_traits:2654:55: error: expected a type
? noexcept(__and_<is_nothrow_move_constructible<_Tp>,
? ^
? /gnu/store/3ka3a9wgx5sk6ac84nldx7ldpxppn29z-profile/include/c++/type_traits:2653:5: error: C++ requires a type specifier for all declarations
? swap(_Tp&, _Tp&)
? ^
? fatal error: too many errors emitted, stopping now [-ferror-limit=]
? 20 errors generated.
?????


4.3 (non desirable) fix of the `CPLUS_INCLUDE_PATH' (removing `/gnu/store/.../include/c++')
???????????????????????????????????????????????????????????????????????????????????????????

For information, it is possible (but obviously in general not
desirable) to fix the `CPLUS_INCLUDE_PATH' variable (removing
`/gnu/store/.../include/c++'), which leads to a correct compilation
(and execution).

?????
? guix environment -C --ad-hoc gcc-toolchain clang-toolchain coreutils grep
? export CPLUS_INCLUDE_PATH=/gnu/store/3ka3a9wgx5sk6ac84nldx7ldpxppn29z-profile/include
? clang++ hello.cpp
? ./a.out
?????

?????
? Hello World!
?????


5 channels
??????????

?????
? guix describe --format=channels
?????

?????
? (list (channel
? (name 'guix-hpc)
? (commit
? "fa87605fe93fb85b02dad9db246299bcf223f2e0"))
? (channel
? (name 'guix-hpc-non-free)
? (commit
? "43d8cb72144a183aa7a93499f9c59ec0f84244b0"))
? (channel
? (name 'guix)
? (commit
? "c6872990b51971922f3064cba54ab752fcdc1559")
? (introduction
? (make-channel-introduction
? "9edb3f66fd807b096b48283debdcddccfea34bad"
? (openpgp-fingerprint
? "BBB0 2DDF 2CEA F6A8 0D1D E643 A2A0 6DF2 A33A 54FA")))))
?????
Attachment: file
L
L
Ludovic Courtès wrote on 22 Oct 2020 10:10
(name . Emmanuel Agullo)(address . emmanuel.agullo@inria.fr)(address . 43023@debbugs.gnu.org)
87v9f2u1eq.fsf@gnu.org
Hi Emmanuel,

Emmanuel Agullo <emmanuel.agullo@inria.fr> skribis:

Toggle quote (5 lines)
> A typical "hello world" C++ fails in an environment with both
> `gcc-toolchain' and `clang-toolchain', apperently due to the setup of
> the `CPLUS_INCLUDE_PATH' environment variable (used because of the
> `#include <iostream>' instruction), when compiling with `clang++'.

Did you want to have both toolchains in the environment, or was the goal
to use Clang, but GCC just happened to be already there (being the
default toolchain)?

In the latter case, the new ‘--with-c-toolchain’ option may help: it
allows you to select ‘clang-toolchain’ instead of the default GCC tool
chain. Note “instead of” rather than “in addition to”, which means that
there’s only one tool chain in the environment, so no risk of
interference.


Now, if you really want the two toolchains in the same environment,
we’ll have to investigate, though I’m not sure it’s even fixable as it
breaks assumptions behind uses of #include_next in libstdc++ and
elsewhere.

Thanks,
Ludo’.
?
Your comment

Commenting via the web interface is currently disabled.

To comment on this conversation send an email to 43023@debbugs.gnu.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 43023
Then, you may apply the latest patchset in this issue (with sign off)
mumi am -- -s
Or, compose a reply to this issue
mumi compose
Or, send patches to this issue
mumi send-email *.patch