File: cxx-invalid-function-decl.cpp

package info (click to toggle)
llvm-toolchain-15 1%3A15.0.6-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,554,644 kB
  • sloc: cpp: 5,922,452; ansic: 1,012,136; asm: 674,362; python: 191,568; objc: 73,855; f90: 42,327; lisp: 31,913; pascal: 11,973; javascript: 10,144; sh: 9,421; perl: 7,447; ml: 5,527; awk: 3,523; makefile: 2,520; xml: 885; cs: 573; fortran: 567
file content (42 lines) | stat: -rw-r--r-- 2,018 bytes parent folder | download | duplicates (29)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// RUN: %clang_cc1 -fsyntax-only -verify %s

// Check that "::new" and "::delete" in member initializer list are diagnosed
// correctly and don't lead to infinite loop on parsing.

// Error: X() (initializer on non-constructor), "::new" is skipped.
void f1() : X() ::new{}; // expected-error{{only constructors take base initializers}}

// Errors: first "::delete" and initializer on non-constructor, others skipped.
void f2() : ::delete, ::new, X() ::new ::delete{} // expected-error{{expected class member or base class name}}
                                                  // expected-error@-1{{only constructors take base initializers}}

// Errors: the '::' token, "::delete" and initializer on non-constructor, others skipped.
void f3() : ::, ::delete X(), ::new {}; // expected-error2{{expected class member or base class name}}
                                        // expected-error@-1{{only constructors take base initializers}}

template <class T>
struct Base1 {
  T x1;
  Base1(T a1) : x1(a1) {}
};

template <class T>
struct Base2 {
  T x2;
  Base2(T a2) : x2(a2) {}
};

struct S : public Base1<int>, public Base2<float> {
  int x;

  // 1-st initializer is correct (just missing ','), 2-nd incorrect, skip other.
  S() : ::Base1<int>(0) ::new, ::Base2<float>(1.0) ::delete x(2) {} // expected-error{{expected class member or base class name}}
                                                                    // expected-error@-1{{missing ',' between base or member initializers}}

  // 1-st and 2-nd are correct, errors: '::' and "::new", others skipped.
  S(int a) : Base1<int>(a), ::Base2<float>(1.0), ::, // expected-error{{expected class member or base class name}}
             ::new, ! ::delete, ::Base2<() x(3) {}   // expected-error{{expected class member or base class name}}

  // All initializers are correct, nothing to skip, diagnose 2 missing commas.
  S(const S &) : Base1<int>(0) ::Base2<float>(1.0) x(2) {} // expected-error2{{missing ',' between base or member initializers}}
};