brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.0 KiB · fc6908f Raw
121 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s2 3namespace GH69890 {4    // If the initializer is (), the object is value-initialized.5    struct A {6        constexpr A() {}7        int x;8    };9 10    struct B : A {11        int y;12    };13 14    static_assert(B().x == 0);15    static_assert(B().y == 0);16} // namespace GH6989017 18namespace P0960R3 {19    struct A { // expected-note 22 {{candidate constructor}}20        int i;21        operator int() volatile;22    };23    volatile A va;24 25    A a1(va);26    A a2 = va; // expected-error {{no matching constructor for initialization of 'A'}}27    A a3 {va};28    A a4 = {va}; // expected-error {{no matching constructor for initialization of 'A'}}29 30    A f() {31        return va; // expected-error {{no matching constructor for initialization of 'A'}}32        return {va}; // expected-error {{no matching constructor for initialization of 'A'}}33    }34 35    int g(A); // expected-note 2 {{passing argument to parameter here}}36    int i = g(va); // expected-error {{no matching constructor for initialization of 'A'}}37    int j = g({va}); // expected-error {{no matching constructor for initialization of 'A'}}38 39    struct Ambig {40        operator const A&(); // expected-note {{candidate function}}41        operator A&&(); // expected-note {{candidate function}}42        operator int();43    };44 45    A a5(Ambig {}); // expected-error {{call to constructor of 'A' is ambiguous}}46    A a6 = Ambig {}; // expected-error {{conversion from 'Ambig' to 'A' is ambiguous}}47    A a7 {Ambig {}};48    A a8 = {Ambig {}};49 50    A a9(1);51    A a10 = 1; // expected-error {{no viable conversion from 'int' to 'A'}}52    A a11 {1};53    A a12 = {1};54 55 56    struct B { // expected-note 12 {{candidate constructor}}57        int i;58        virtual operator int() volatile;59    };60    volatile B vb;61 62    B b1(vb); // expected-error {{no matching constructor for initialization of 'B'}}63    B b2 = vb; // expected-error {{no matching constructor for initialization of 'B'}}64    B b3 {vb}; // expected-error {{no matching constructor for initialization of 'B'}}65    B b4 = {vb}; // expected-error {{no matching constructor for initialization of 'B'}}66 67 68    struct Immovable {69        Immovable();70        Immovable(const Immovable&) = delete; // #Imm_copy71    };72 73    struct C { // #C74        int i;75        Immovable j; // #C_j76 77        operator int() volatile;78    };79    C c;80    volatile C vc;81 82    C c1(c); // expected-error {{call to implicitly-deleted copy constructor of 'C'}}83    C c2 = c; // expected-error {{call to implicitly-deleted copy constructor of 'C'}}84    C c3 {c}; // expected-error {{call to implicitly-deleted copy constructor of 'C'}}85    C c4 = {c}; // expected-error {{call to implicitly-deleted copy constructor of 'C'}}86    // expected-note@#C_j 4 {{copy constructor of 'C' is implicitly deleted}}87    // expected-note@#Imm_copy 4 {{'Immovable' has been explicitly marked deleted here}}88 89    C c5(vc);90    C c6 = vc; // expected-error {{no matching constructor for initialization of 'C'}}91    C c7 {vc};92    C c8 = {vc}; // expected-error {{no matching constructor for initialization of 'C'}}93    // expected-note@#C 4 {{candidate constructor}}94 95    C c9(C {});96    C c10 = C(123);97    C c11 {C {0, Immovable()}};98    C c12 = {C()};99 100 101    struct D { // expected-note 6 {{candidate constructor}}102        int i;103    };104 105    struct DD : private D { // expected-note 4 {{declared private here}}106        virtual operator int() volatile;107    };108    DD dd;109    volatile DD vdd;110 111    D d1(dd); // expected-error {{cannot cast 'const DD' to its private base class 'const D'}}112    D d2 = dd; // expected-error {{cannot cast 'const DD' to its private base class 'const D'}}113    D d3 {dd}; // expected-error {{cannot cast 'const DD' to its private base class 'const D'}}114    D d4 = {dd}; // expected-error {{cannot cast 'const DD' to its private base class 'const D'}}115 116    D d5(vdd);117    D d6 = vdd; // expected-error {{no matching constructor for initialization of 'D'}}118    D d7 {vdd};119    D d8 = {vdd}; // expected-error {{no matching constructor for initialization of 'D'}}120} // namespace P0960R3121