|
2 | 2 | // RUN: %clang_cc1 -std=c++11 %s -verify=expected,since-cxx11,cxx98-11,cxx98-14,cxx98-17 -fexceptions -fcxx-exceptions -pedantic-errors
|
3 | 3 | // RUN: %clang_cc1 -std=c++14 %s -verify=expected,since-cxx11,since-cxx14,cxx98-14,cxx98-17 -fexceptions -fcxx-exceptions -pedantic-errors
|
4 | 4 | // RUN: %clang_cc1 -std=c++17 %s -verify=expected,since-cxx11,since-cxx14,since-cxx17,cxx98-17 -fexceptions -fcxx-exceptions -pedantic-errors
|
5 |
| -// RUN: %clang_cc1 -std=c++20 %s -verify=expected,since-cxx11,since-cxx14,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors |
6 |
| -// RUN: %clang_cc1 -std=c++23 %s -verify=expected,since-cxx11,since-cxx14,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors |
7 |
| -// RUN: %clang_cc1 -std=c++2c %s -verify=expected,since-cxx11,since-cxx14,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors |
| 5 | +// RUN: %clang_cc1 -std=c++20 %s -verify=expected,since-cxx11,since-cxx14,since-cxx17,since-cxx20 -fexceptions -fcxx-exceptions -pedantic-errors |
| 6 | +// RUN: %clang_cc1 -std=c++23 %s -verify=expected,since-cxx11,since-cxx14,since-cxx17,since-cxx20 -fexceptions -fcxx-exceptions -pedantic-errors |
| 7 | +// RUN: %clang_cc1 -std=c++2c %s -verify=expected,since-cxx11,since-cxx14,since-cxx17,since-cxx20 -fexceptions -fcxx-exceptions -pedantic-errors |
8 | 8 |
|
9 | 9 | // FIXME: diagnostic above is emitted only on Windows platforms
|
10 | 10 | // PR13819 -- __SIZE_TYPE__ is incompatible.
|
@@ -42,6 +42,141 @@ namespace cwg202 { // cwg202: 3.1
|
42 | 42 | template struct X<f>;
|
43 | 43 | } // namespace cwg202
|
44 | 44 |
|
| 45 | +namespace cwg203 { // cwg203: 3.0 |
| 46 | +namespace ex1 { |
| 47 | +struct B { |
| 48 | + int i; |
| 49 | +}; |
| 50 | +struct D1 : B {}; |
| 51 | +struct D2 : B {}; |
| 52 | + |
| 53 | +int(D1::*pmD1) = &D2::i; |
| 54 | +} // namespace ex1 |
| 55 | + |
| 56 | +#if __cplusplus >= 202002L |
| 57 | +namespace ex2 { |
| 58 | +struct A { |
| 59 | + int i; |
| 60 | + virtual void f() = 0; // #cwg203-ex2-A-f |
| 61 | +}; |
| 62 | + |
| 63 | +struct B : A { |
| 64 | + int j; |
| 65 | + constexpr B() : j(5) {} |
| 66 | + virtual void f(); |
| 67 | +}; |
| 68 | + |
| 69 | +struct C : B { |
| 70 | + constexpr C() { j = 10; } |
| 71 | +}; |
| 72 | + |
| 73 | +template <class T> |
| 74 | +constexpr int DefaultValue(int(T::*m)) { |
| 75 | + return T().*m; |
| 76 | + // since-cxx20-error@-1 {{allocating an object of abstract class type 'cwg203::ex2::A'}} |
| 77 | + // since-cxx20-note@#cwg203-ex2-a {{in instantiation of function template specialization 'cwg203::ex2::DefaultValue<cwg203::ex2::A>' requested here}} |
| 78 | + // since-cxx20-note@#cwg203-ex2-A-f {{unimplemented pure virtual method 'f' in 'A'}} |
| 79 | +} // #cwg203-ex2-DefaultValue |
| 80 | + |
| 81 | +int a = DefaultValue(&B::i); // #cwg203-ex2-a |
| 82 | +static_assert(DefaultValue(&C::j) == 5, ""); |
| 83 | +} // namespace ex2 |
| 84 | +#endif |
| 85 | + |
| 86 | +namespace ex3 { |
| 87 | +class Base { |
| 88 | +public: |
| 89 | + int func() const; |
| 90 | +}; |
| 91 | + |
| 92 | +class Derived : public Base {}; |
| 93 | + |
| 94 | +template <class T> class Templ { // #cwg203-ex3-Templ |
| 95 | +public: |
| 96 | + template <class S> Templ(S (T::*ptmf)() const); // #cwg203-ex3-Templ-ctor |
| 97 | +}; |
| 98 | + |
| 99 | +void foo() { Templ<Derived> x(&Derived::func); } |
| 100 | +// expected-error@-1 {{no matching constructor for initialization of 'Templ<Derived>'}} |
| 101 | +// expected-note@#cwg203-ex3-Templ {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int (cwg203::ex3::Base::*)() const' to 'const Templ<Derived>' for 1st argument}} |
| 102 | +// since-cxx11-note@#cwg203-ex3-Templ {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'int (cwg203::ex3::Base::*)() const' to 'Templ<Derived>' for 1st argument}} |
| 103 | +// expected-note@#cwg203-ex3-Templ-ctor {{candidate template ignored: could not match 'cwg203::ex3::Derived' against 'cwg203::ex3::Base'}} |
| 104 | +} // namespace ex3 |
| 105 | + |
| 106 | +namespace ex4 { |
| 107 | +struct Very_base { |
| 108 | + int a; |
| 109 | +}; |
| 110 | +struct Base1 : Very_base {}; |
| 111 | +struct Base2 : Very_base {}; |
| 112 | +struct Derived : Base1, Base2 { |
| 113 | +}; |
| 114 | + |
| 115 | +int f() { |
| 116 | + Derived d; |
| 117 | + // FIXME: in the diagnostic below, Very_base is fully qualified, but Derived is not |
| 118 | + int Derived::*a_ptr = &Derived::Base1::a; |
| 119 | + /* expected-error@-1 |
| 120 | + {{ambiguous conversion from pointer to member of base class 'cwg203::ex4::Very_base' to pointer to member of derived class 'Derived': |
| 121 | + struct cwg203::ex4::Derived -> Base1 -> Very_base |
| 122 | + struct cwg203::ex4::Derived -> Base2 -> Very_base}}*/ |
| 123 | +} |
| 124 | +} // namespace ex4 |
| 125 | + |
| 126 | +namespace ex5 { |
| 127 | +struct Base { |
| 128 | + int a; |
| 129 | +}; |
| 130 | +struct Derived : Base { |
| 131 | + int b; |
| 132 | +}; |
| 133 | + |
| 134 | +template <typename Class, typename Member_type, Member_type Base::*ptr> |
| 135 | +Member_type get(Class &c) { |
| 136 | + return c.*ptr; |
| 137 | +} |
| 138 | + |
| 139 | +void call(int (*f)(Derived &)); // #cwg203-ex5-call |
| 140 | + |
| 141 | +int f() { |
| 142 | + // ill-formed, contrary to Core issue filing: |
| 143 | + // `&Derived::b` yields `int Derived::*`, which can't initialize NTTP of type `int Base::*`, |
| 144 | + // because (implicit) pointer-to-member conversion doesn't upcast. |
| 145 | + call(&get<Derived, int, &Derived::b>); |
| 146 | + // expected-error@-1 {{no matching function for call to 'call'}} |
| 147 | + // expected-note@#cwg203-ex5-call {{candidate function not viable: no overload of 'get' matching 'int (*)(Derived &)' for 1st argument}} |
| 148 | + |
| 149 | + // well-formed, contrary to Core issue filing: |
| 150 | + // `&Derived::a` yields `int Base::*`, |
| 151 | + // which can initialize NTTP of type `int Base::*`. |
| 152 | + call(&get<Derived, int, &Derived::a>); |
| 153 | + |
| 154 | + call(&get<Base, int, &Derived::a>); |
| 155 | + // expected-error@-1 {{no matching function for call to 'call'}} |
| 156 | + // expected-note@#cwg203-ex5-call {{candidate function not viable: no overload of 'get' matching 'int (*)(Derived &)' for 1st argument}} |
| 157 | +} |
| 158 | +} // namespace ex5 |
| 159 | + |
| 160 | +namespace ex6 { |
| 161 | +struct Base { |
| 162 | + int a; |
| 163 | +}; |
| 164 | +struct Derived : private Base { // #cwg203-ex6-Derived |
| 165 | +public: |
| 166 | + using Base::a; // make `a` accessible |
| 167 | +}; |
| 168 | + |
| 169 | +int f() { |
| 170 | + Derived d; |
| 171 | + int b = d.a; |
| 172 | + // FIXME: in the diagnostic below, Base is fully qualified, but Derived is not |
| 173 | + int Derived::*ptr = &Derived::a; |
| 174 | + // expected-error@-1 {{cannot cast private base class 'cwg203::ex6::Base' to 'Derived'}} |
| 175 | + // expected-note@#cwg203-ex6-Derived {{declared private here}} |
| 176 | +} |
| 177 | +} // namespace ex6 |
| 178 | +} // namespace cwg203 |
| 179 | + |
45 | 180 | // cwg204: sup 820
|
46 | 181 |
|
47 | 182 | namespace cwg206 { // cwg206: 2.7
|
|
0 commit comments