- 
                Notifications
    
You must be signed in to change notification settings  - Fork 15.1k
 
Open
Labels
clang:frontendLanguage frontend issues, e.g. anything involving "Sema"Language frontend issues, e.g. anything involving "Sema"conceptsC++20 conceptsC++20 conceptscwg-issueAn issue that was filed to the Core Working GroupAn issue that was filed to the Core Working Grouplibstdc++GNU libstdc++ C++ standard libraryGNU libstdc++ C++ standard library
Description
The following code does not build:
#include <variant>
struct X {
    struct A { int a=0; };
    struct B {
        std::variant<X::A> a;
    };
};
void test() {
    X::B b;
}
See https://godbolt.org/z/4ExGEvTf6 (on clang-trunk, with -std=c++20 -O2).
The error is:
<source>:11:10: error: call to implicitly-deleted default constructor of 'X::B'
   11 |     X::B b;
      |          ^
<source>:6:28: note: default constructor of 'B' is implicitly deleted because field 'a' has no default constructor
    6 |         std::variant<X::A> a;
      |                            ^
Each of the following changes will make the code compile:
- making A and B top-level classes
 - Changing class A to not have an initializer for a
 - Changing class A to have an explicit constructor (like 
A() : a(0) {}) 
I think this code should be accepted. GCC accepts this code since version 14.1 (previous versions reject it with an error message similar to clang's message).
Metadata
Metadata
Assignees
Labels
clang:frontendLanguage frontend issues, e.g. anything involving "Sema"Language frontend issues, e.g. anything involving "Sema"conceptsC++20 conceptsC++20 conceptscwg-issueAn issue that was filed to the Core Working GroupAn issue that was filed to the Core Working Grouplibstdc++GNU libstdc++ C++ standard libraryGNU libstdc++ C++ standard library