File: elaborated-type-specifier.cpp

package info (click to toggle)
llvm-toolchain-16 1%3A16.0.6-15~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,634,792 kB
  • sloc: cpp: 6,179,261; ansic: 1,216,205; asm: 741,319; python: 196,614; objc: 75,325; f90: 49,640; lisp: 32,396; pascal: 12,286; sh: 9,394; perl: 7,442; ml: 5,494; awk: 3,523; makefile: 2,723; javascript: 1,206; xml: 886; fortran: 581; cs: 573
file content (63 lines) | stat: -rw-r--r-- 1,832 bytes parent folder | download | duplicates (14)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// RUN: %clang_cc1 -fsyntax-only -verify %s

// Test the use of elaborated-type-specifiers to inject the names of
// structs (or classes or unions) into an outer scope as described in
// C++ [basic.scope.pdecl]p5.
typedef struct S1 {
  union {
    struct S2 *x;
    struct S3 *y;
  };
} S1;

bool test_elab(S1 *s1, struct S2 *s2, struct S3 *s3) {
  if (s1->x == s2) return true;
  if (s1->y == s3) return true;
  return false;
}

namespace NS {
  class X {
  public:
    void test_elab2(struct S4 *s4); // expected-note{{'NS::S4' declared here}}
  };

  void X::test_elab2(S4 *s4) { } // expected-note{{passing argument to parameter 's4' here}}
}

void test_X_elab(NS::X x) {
  struct S4 *s4 = 0; // expected-note{{'S4' is not defined, but forward declared here; conversion would be valid if it was derived from 'NS::S4'}}
  x.test_elab2(s4); // expected-error{{cannot initialize a parameter of type 'S4 *' (aka 'NS::S4 *') with an lvalue of type 'struct S4 *'}}
}

namespace NS {
  S4 *get_S4();
}

void test_S5_scope() {
  S4 *s4; // expected-error{{unknown type name 'S4'; did you mean 'NS::S4'?}}
}

int test_funcparam_scope(struct S5 * s5) {
  struct S5 { int y; } *s5_2 = 0;
  if (s5 == s5_2) return 1; // expected-error {{comparison of distinct pointer types ('struct S5 *' and 'struct S5 *')}}
  return 0;
}

namespace test5 {
  struct A {
    class __attribute__((visibility("hidden"))) B {};

    void test(class __attribute__((visibility("hidden"), noreturn)) B b) { // expected-warning {{'noreturn' attribute only applies to functions and methods}}
    }
  };
}

namespace test6 {
struct C {
  template <typename> friend struct A; // expected-note {{'A' declared here}}
};
struct B {
  struct A *p; // expected-error {{implicit declaration introduced by elaborated type conflicts with a template of the same name}}
};
}