1 // RUN: %clang_cc1 -fsyntax-only -verify %s
2
3 // Check that "::new" and "::delete" in member initializer list are diagnosed
4 // correctly and don't lead to infinite loop on parsing.
5
6 // Error: X() (initializer on non-constructor), "::new" is skipped.
f1()7 void f1() : X() ::new{}; // expected-error{{only constructors take base initializers}}
8
9 // Errors: first "::delete" and initializer on non-constructor, others skipped.
f2()10 void f2() : ::delete, ::new, X() ::new ::delete{} // expected-error{{expected class member or base class name}}
11 // expected-error@-1{{only constructors take base initializers}}
12
13 // Errors: the '::' token, "::delete" and initializer on non-constructor, others skipped.
f3()14 void f3() : ::, ::delete X(), ::new {}; // expected-error2{{expected class member or base class name}}
15 // expected-error@-1{{only constructors take base initializers}}
16
17 template <class T>
18 struct Base1 {
19 T x1;
Base1Base120 Base1(T a1) : x1(a1) {}
21 };
22
23 template <class T>
24 struct Base2 {
25 T x2;
Base2Base226 Base2(T a2) : x2(a2) {}
27 };
28
29 struct S : public Base1<int>, public Base2<float> {
30 int x;
31
32 // 1-st initializer is correct (just missing ','), 2-nd incorrect, skip other.
SS33 S() : ::Base1<int>(0) ::new, ::Base2<float>(1.0) ::delete x(2) {} // expected-error{{expected class member or base class name}}
34 // expected-error@-1{{missing ',' between base or member initializers}}
35
36 // 1-st and 2-nd are correct, errors: '::' and "::new", others skipped.
SS37 S(int a) : Base1<int>(a), ::Base2<float>(1.0), ::, // expected-error{{expected class member or base class name}}
38 ::new, ! ::delete, ::Base2<() x(3) {} // expected-error{{expected class member or base class name}}
39
40 // All initializers are correct, nothing to skip, diagnose 2 missing commas.
SS41 S(const S &) : Base1<int>(0) ::Base2<float>(1.0) x(2) {} // expected-error2{{missing ',' between base or member initializers}}
42 };
43