summaryrefslogtreecommitdiffstats
path: root/build/clang-plugin/tests/TestTrivialCtorDtor.cpp
blob: a1038b6e63ee953cf521430ff0d0aa040c5cf8c8 (plain)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#define MOZ_TRIVIAL_CTOR_DTOR __attribute__((annotate("moz_trivial_ctor_dtor")))

struct MOZ_TRIVIAL_CTOR_DTOR EmptyClass{};

template <class T>
struct MOZ_TRIVIAL_CTOR_DTOR TemplateEmptyClass{};

struct MOZ_TRIVIAL_CTOR_DTOR NonEmptyClass {
  void *m;
};

template <class T>
struct MOZ_TRIVIAL_CTOR_DTOR TemplateNonEmptyClass {
  T* m;
};

struct MOZ_TRIVIAL_CTOR_DTOR BadUserDefinedCtor { // expected-error {{class 'BadUserDefinedCtor' must have trivial constructors and destructors}}
  BadUserDefinedCtor() {}
};

struct MOZ_TRIVIAL_CTOR_DTOR BadUserDefinedDtor { // expected-error {{class 'BadUserDefinedDtor' must have trivial constructors and destructors}}
  ~BadUserDefinedDtor() {}
};

struct MOZ_TRIVIAL_CTOR_DTOR BadVirtualDtor { // expected-error {{class 'BadVirtualDtor' must have trivial constructors and destructors}}
  virtual ~BadVirtualDtor() {}
};

struct MOZ_TRIVIAL_CTOR_DTOR OkVirtualMember {
  virtual void f();
};

void foo();
struct MOZ_TRIVIAL_CTOR_DTOR BadNonEmptyCtorDtor { // expected-error {{class 'BadNonEmptyCtorDtor' must have trivial constructors and destructors}}
  BadNonEmptyCtorDtor() { foo(); }
  ~BadNonEmptyCtorDtor() { foo(); }
};

struct NonTrivialCtor {
  NonTrivialCtor() { foo(); }
};

struct NonTrivialDtor {
  ~NonTrivialDtor() { foo(); }
};

struct VirtualMember {
  virtual void f();
};

struct MOZ_TRIVIAL_CTOR_DTOR BadNonTrivialCtorInBase : NonTrivialCtor { // expected-error {{class 'BadNonTrivialCtorInBase' must have trivial constructors and destructors}}
};

struct MOZ_TRIVIAL_CTOR_DTOR BadNonTrivialDtorInBase : NonTrivialDtor { // expected-error {{class 'BadNonTrivialDtorInBase' must have trivial constructors and destructors}}
};

struct MOZ_TRIVIAL_CTOR_DTOR BadNonTrivialCtorInMember { // expected-error {{class 'BadNonTrivialCtorInMember' must have trivial constructors and destructors}}
  NonTrivialCtor m;
};

struct MOZ_TRIVIAL_CTOR_DTOR BadNonTrivialDtorInMember { // expected-error {{class 'BadNonTrivialDtorInMember' must have trivial constructors and destructors}}
  NonTrivialDtor m;
};

struct MOZ_TRIVIAL_CTOR_DTOR OkVirtualMemberInMember {
  VirtualMember m;
};

struct MOZ_TRIVIAL_CTOR_DTOR OkConstExprConstructor {
  constexpr OkConstExprConstructor() {}
};

struct MOZ_TRIVIAL_CTOR_DTOR OkConstExprConstructorInMember {
  OkConstExprConstructor m;
};

#if __cplusplus >= 202002L
struct
#else
// XXX: This error is unfortunate, but is unlikely to come up in real code.
// In this situation, it should be possible to define a constexpr constructor
// which explicitly initializes the members.
struct // expected-error {{class 'BadUnfortunateError' must have trivial constructors and destructors}}
#endif
MOZ_TRIVIAL_CTOR_DTOR BadUnfortunateError {
  OkConstExprConstructor m;
  void *n;
};