Bug 97449 - [11 Regression] libstdc++ <variant> cannot be compiled with clang after 3427e31331677ca826c5588c87924214f7e5c54b
Summary: [11 Regression] libstdc++ <variant> cannot be compiled with clang after 3427e...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 11.0
: P1 normal
Target Milestone: 11.0
Assignee: Ville Voutilainen
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2020-10-15 16:47 UTC by James Y Knight
Modified: 2020-10-17 20:12 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work: 10.2.1
Known to fail: 11.0
Last reconfirmed: 2020-10-15 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description James Y Knight 2020-10-15 16:47:31 UTC
After 3427e31331677ca826c5588c87924214f7e5c54b, "clang -std=c++17" (using libstdc++ headers), on a file that has simply "#include <variant>" fails with this error:

In file included from <source>:1:

/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/11.0.0/../../../../include/c++/11.0.0/variant:1032:10: error: no matching constructor for initialization of 'std::__nonesuch'
                return __nonesuch{};
                       ^         ~~

/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/11.0.0/../../../../include/c++/11.0.0/type_traits:2953:5: note: candidate constructor not viable: requires 1 argument, but 0 were provided
    __nonesuch(__nonesuch const&) = delete;
    ^

(https://godbolt.org/z/951jYr)

I believe Clang is correct to reject this code, due to http://eel.is/c++draft/temp.res#general-8.1
"""
The program is ill-formed, no diagnostic required, if:
- no valid specialization can be generated for a template or a substatement of a constexpr if statement within a template and the template is not instantiated
"""

The invalid return statement probably needs to be made dependent on __visit_ret_type_mismatch just like the static_assert.
Comment 1 Ville Voutilainen 2020-10-15 18:36:10 UTC
Mine. I have a patch for it already, doing testing and submission chores...
Comment 2 Ville Voutilainen 2020-10-16 07:28:29 UTC
Patch available: https://gcc.gnu.org/pipermail/gcc-patches/2020-October/556323.html
Comment 3 GCC Commits 2020-10-17 20:11:02 UTC
The master branch has been updated by Ville Voutilainen <ville@gcc.gnu.org>:

https://gcc.gnu.org/g:1f65bf2aa65609c0cd88af1b83191d37d6729f46

commit r11-4024-g1f65bf2aa65609c0cd88af1b83191d37d6729f46
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date:   Sat Oct 17 22:08:50 2020 +0300

    libstdc++: Fix visitor return type diagnostics [PR97449]
    
    libstdc++-v3/ChangeLog:
    
            PR libstdc++/97449
            * include/std/variant
            (__gen_vtable_impl<>::_S_apply_single_alt):
            Diagnose visitor return type mismatches here..
            (__gen_vtable_impl</*base case*/>::_S_apply):
            ..not here.
Comment 4 Ville Voutilainen 2020-10-17 20:12:21 UTC
Fixed.