| 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. |
| 7 |
void f1() : X() ::new{}; // expected-error{{only constructors take base initializers}} |
| 8 |
|
| 9 |
// Errors: first "::delete" and initializer on non-constructor, others skipped. |
| 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. |
| 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; |
| 20 |
Base1(T a1) : x1(a1) {} |
| 21 |
}; |
| 22 |
|
| 23 |
template <class T> |
| 24 |
struct Base2 { |
| 25 |
T x2; |
| 26 |
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. |
| 33 |
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. |
| 37 |
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. |
| 41 |
S(const S &) : Base1<int>(0) ::Base2<float>(1.0) x(2) {} // expected-error2{{missing ',' between base or member initializers}} |
| 42 |
}; |
| 43 |
|
| 44 |
namespace GH113722 { |
| 45 |
struct S { |
| 46 |
void m(int x = 0; // expected-error {{unexpected end of default argument expression}} \ |
| 47 |
expected-note {{to match this '('}} |
| 48 |
#pragma unused(x) // expected-error {{expected ')'}} \ |
| 49 |
expected-error {{expected ';' at end of declaration list}} |
| 50 |
} // expected-error {{expected ';' after struct}} |
| 51 |
}; |
| 52 |
} // expected-error {{extraneous closing brace ('}')}} |