Clang Project

clang_source_code/test/SemaCXX/anonymous-struct.cpp
1// RUN: %clang_cc1 -fsyntax-only -verify %s
2// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
3// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
4
5struct S {
6  S();
7#if __cplusplus <= 199711L
8  // expected-note@-2 {{because type 'S' has a user-provided default constructor}}
9#endif
10};
11
12struct { // expected-error {{anonymous structs and classes must be class members}}
13};
14
15struct E {
16  struct {
17    S x;
18#if __cplusplus <= 199711L
19    // expected-error@-2 {{anonymous struct member 'x' has a non-trivial default constructor}}
20#endif
21  };
22  static struct {
23  };
24  class {
25    int anon_priv_field; // expected-error {{anonymous struct cannot contain a private data member}}
26  };
27};
28
29template <class T> void foo(T);
30typedef struct { // expected-note {{use a tag name here to establish linkage prior to definition}}
31#if __cplusplus <= 199711L
32// expected-note@-2 {{declared here}}
33#endif
34
35  void test() {
36    foo(this);
37#if __cplusplus <= 199711L
38    // expected-warning@-2 {{template argument uses unnamed type}}
39#endif
40  }
41} A; // expected-error {{unsupported: typedef changes linkage of anonymous type, but linkage was already computed}}
42