-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Compilation error for std::variant using GCC's 7.1 libstdc++ #32569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Could this get some more attention, please? This makes unusable for the clang + libstdc++ combo, requiring either Boost.Variant or libc++. |
I'm also affected by this. I reported this to debian BTS as well: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=877838 With the help of creduce, here's a "minimal" test-case that shows the problem: $ cat variant.cpp template } template class variant { int main() { $ g++-7 variant.cpp -std=c++1z I suspect this might be related to the use of decltype(auto): if I change decltype(auto) to (e.g.) int, it works. Thanks, Daniele |
This prevents This is a pretty major roadblock - is this being looked into? |
Minimal example to reproduce this:
This compiles on g++, but fails to compile on clang++ trunk. Note that calling |
I've added a workaround in https://gcc.gnu.org/r258854 |
Further reduced, this gives a 'conflicting types' error for 'foo': auto foo(); |
Even this is rejected: int f(); It looks like the function template and non-template function cases are actually two distinct bugs. |
Comment#0 / comment#4 / comment#6 bugs fixed in r341778. |
Richard are these patches OK to merge to the release_70 branch? |
Yes. |
Merged: r345409 r345412 |
Using gcc-9's libstdc++, which changed the check from So it appears to not be fixed in clang-8. |
My bad, it only reports the same problem again because of the missing |
That was Bug 41863 which has similar symptoms. |
Using libstdc++-9.1 fails for clang++-6.0 but not for clang++-7, clang++-8 and clang++-9 SVN. |
mentioned in issue #38454 |
CI currently skips these because there is no host Swift anyway. Forcefully skip them to allow using the release docker images as the base image (with Clang and Swift pre-installed). CentOS 7 needs this as the packaged Clang (in software collections) is only Clang 5. It does technically support C++17 but has a bug causing a compiler error for most uses of `variant` (now used all throughout LLVM) - llvm/llvm-project#32569. This is temporary as the bootstrap should work. It currently fails when linking `libswiftDemangle.so`, which tries to link with `swiftCore`, but fails to find it. Need to look into that, but this is an easy fix that doesn't regress anything for now.
std::variant is broken in clang < 7.0.1 with libstdc++ see: llvm/llvm-project#32569
std::variant is broken in clang < 7.0.1 with libstdc++ see: llvm/llvm-project#32569
std::variant is broken in clang < 7.0.1 with libstdc++ see: llvm/llvm-project#32569
std::variant is broken in clang < 7.0.1 with libstdc++ see: llvm/llvm-project#32569
Extended Description
Simple std::variant code, compilation fails at line caling std::visit both with clang-4.0 and trunk. With GCC-7.1 compiles fine.
// CODE:
#include
struct A {};
struct B {};
struct Visitor
{
auto operator ()(A) -> void {}
auto operator ()(B) -> void {}
};
auto main() -> int
{
auto variant = std::variant<A, B>{ A{} };
visit(Visitor{}, variant);
}
// COMPILATION OUTPUT (STRIPPED):
$ clang++ -std=c++1z variant.cpp
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/7.1.1/../../../../include/c++/7.1.1/variant:235:46: error: cannot cast 'std::variant<A, B>' to its private base class 'std::__detail::__variant::_Variant_storage<true, A, B>'
return __get(std::in_place_index<_Np>, std::forward<_Variant>(__v)._M_u);
// MY THOUGHTS:
std::variant contains friend declaration in its body:
https://github.com/gcc-mirror/gcc/blob/gcc-7_1_0-release/libstdc%2B%2B-v3/include/std/variant#L1154
for some reason it is ignored when compiling std::__detail::__variant::_get
https://github.com/gcc-mirror/gcc/blob/gcc-7_1_0-release/libstdc%2B%2B-v3/include/std/variant#L232
I'm not sure whether it's clang or libstdc++ bug
// SOFTWARE VERSIONS:
$ clang -v
clang version 4.0.0 (tags/RELEASE_400/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-pc-linux-gnu/7.1.1
Found candidate GCC installation: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/7.1.1
Found candidate GCC installation: /usr/lib/gcc/x86_64-pc-linux-gnu/7.1.1
Found candidate GCC installation: /usr/lib64/gcc/x86_64-pc-linux-gnu/7.1.1
Selected GCC installation: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/7.1.1
Candidate multilib: .;@m64
Selected multilib: .;@m64
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
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/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 --disable-multilib --disable-werror --enable-checking=release
Thread model: posix
gcc version 7.1.1 20170516 (GCC)
The text was updated successfully, but these errors were encountered: