1 // RUN: %clang_cc1 -Wreorder -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -Wreorder -fsyntax-only -verify -std=c++98 %s
3 // RUN: %clang_cc1 -Wreorder -fsyntax-only -verify -std=c++11 %s
8 A() : A::m(17) { } // expected-error {{member initializer 'm' does not name a non-static data member or base class}}
14 B() : A(), m(1), n(3.14) { }
22 class C
: public virtual B
{
32 class E
: public D
, public B
{ // expected-warning{{direct base 'B' is inaccessible due to ambiguity:\n class E -> class D -> class C -> class B\n class E -> class B}}
34 E() : B(), D() { } // expected-error{{base class initializer 'B' names both a direct base class and an inherited virtual base class}}
45 m(17), // expected-error{{member initializer 'm' does not name a non-static data member or base class}}
46 INT(17) // expected-error{{constructor initializer 'INT' (aka 'int') does not name a class}}
52 G() : A(10); // expected-error{{expected '{'}}
55 void f() : a(242) { } // expected-error{{only constructors take base initializers}}
67 struct S
: Y
, virtual X
{
72 Z() : X(), S(), E() {} // expected-error {{type 'E' is not a direct or virtual base of 'Z'}}
76 union { int a
; char* p
; };
77 union { int b
; double d
; };
79 U() : a(1), // expected-note {{previous initialization is here}}
80 p(0), // expected-error {{initializing multiple members of union}}
88 struct Derived
: Base
, Base1
, virtual V
{
92 struct Current
: Derived
{
94 Current() : Derived(1), ::Derived(), // expected-warning {{initializer order does not match the declaration order}} \
95 // expected-note {{field 'Derived' will be initialized after base '::Derived'}} \
96 // expected-note {{base class '::Derived' will be initialized after base 'Derived::V'}}
97 ::Derived::Base(), // expected-error {{type '::Derived::Base' is not a direct or virtual base of 'Current'}}
98 Derived::Base1(), // expected-error {{type 'Derived::Base1' is not a direct or virtual base of 'Current'}}
100 ::NonExisting(), // expected-error {{member initializer 'NonExisting' does not name a non-static data member or}}
101 INT::NonExisting() {} // expected-error {{'INT' (aka 'int') is not a class, namespace, or enumeration}} \
102 // expected-error {{member initializer 'NonExisting' does not name a non-static data member or}}
105 struct M
{ // expected-note 2 {{candidate constructor (the implicit copy constructor)}}
106 #if __cplusplus >= 201103L // C++11 or later
107 // expected-note@-2 2 {{candidate constructor (the implicit move constructor) not viable}}
109 // expected-note@-4 2 {{'M' declared here}}
110 M(int i
, int j
); // expected-note 2 {{candidate constructor}}
114 N() : M(1), // expected-error {{no matching constructor for initialization of 'M'}}
115 m1(100) { } // expected-error {{no matching constructor for initialization of 'M'}}
120 P() { } // expected-error {{constructor for 'P' must explicitly initialize the base class 'M' which does not have a default constructor}} \
121 // expected-error {{member 'm'}}
122 M m
; // expected-note {{member is declared here}}
126 Q() : f1(1,2), // expected-error {{excess elements in scalar initializer}}
127 pf(0.0) { } // expected-error {{cannot initialize a member subobject of type 'float *' with an rvalue of type 'double'}}
133 // A silly class used to demonstrate field-is-uninitialized in constructors with
135 int IntParam(int i
) { return 0; };
136 class TwoInOne
{ public: TwoInOne(TwoInOne a
, TwoInOne b
) {} };
137 class InitializeUsingSelfTest
{
143 InitializeUsingSelfTest(int F
)
144 : A(A
), // expected-warning {{field 'A' is uninitialized when used here}}
145 B((((B
)))), // expected-warning {{field 'B' is uninitialized when used here}}
146 C(A
&& InitializeUsingSelfTest::C
), // expected-warning {{field 'C' is uninitialized when used here}}
147 D(D
, // expected-warning {{field 'D' is uninitialized when used here}}
148 D
), // expected-warning {{field 'D' is uninitialized when used here}}
149 E(IntParam(E
)) {} // expected-warning {{field 'E' is uninitialized when used here}}
152 int IntWrapper(int &i
) { return 0; };
153 class InitializeUsingSelfExceptions
{
158 InitializeUsingSelfExceptions(int B
)
159 : A(IntWrapper(A
)), // Due to a conservative implementation, we do not report warnings inside function/ctor calls even though it is possible to do so.
160 B(B
), // Not a warning; B is a local variable.
161 C(sizeof(C
)), // sizeof doesn't reference contents, do not warn
162 P(&P
) {} // address-of doesn't reference contents (the pointer may be dereferenced in the same expression but it would be rare; and weird)
165 class CopyConstructorTest
{
167 CopyConstructorTest(const CopyConstructorTest
& rhs
)
169 B(B
), // expected-warning {{field 'B' is uninitialized when used here}}
170 C(rhs
.C
|| C
) { } // expected-warning {{field 'C' is uninitialized when used here}}
173 // Make sure we aren't marking default constructors when we shouldn't be.
179 NDC(T
&ref
) : ref(ref
) { }
182 struct X0
: NDC
<int> {
183 X0(int &ref
) : NDC
<int>(ref
), ndc(ref
) { }
201 enum Kind
{ Foo
} Kind
;
212 struct B
: virtual A
{ };
214 struct C
: A
, B
{ }; // expected-warning{{direct base 'Test2::A' is inaccessible due to ambiguity:\n struct Test2::C -> struct Test2::A\n struct Test2::C -> struct Test2::B -> struct Test2::A}}
222 // Don't build implicit initializers for anonymous union fields when we already
223 // have an explicit initializer for another field in the union.
231 template <typename T
> S(T
) : ptr_(0) { }
239 // <rdar://problem/8308215>: don't crash.
240 // Lots of questionable recovery here; errors can change.
242 class A
: public std::exception
{}; // expected-error {{undeclared identifier}} expected-error {{expected class name}}
243 // expected-note@-1 {{candidate constructor (the implicit copy constructor) not viable}}
244 #if __cplusplus >= 201103L // C++11 or later
245 // expected-note@-3 {{candidate constructor (the implicit move constructor) not viable}}
247 // expected-note@-5 {{candidate constructor (the implicit default constructor) not viable}}
251 B(const String
& s
, int e
=0) // expected-error {{unknown type name}}
252 : A(e
), m_String(s
) , m_ErrorStr(__null
) {} // expected-error {{no matching constructor}} \
253 expected
-error
{{member initializer
'm_String' does
not name
}} \
254 expected
-error
{{member initializer
'm_ErrorStr' does
not name
}}
256 : A(e
), m_String(e
.m_String
), m_ErrorStr(__null
) { // expected-error 2{{does not name}} \
257 // expected-error {{no member named 'm_String' in 'test3::B'}}
267 static const int bar
= 42;
286 S4() : s1(s1
.baz()) {}
297 Class() : member(function() {} // expected-note {{to match this '('}}
299 int member
; // expected-error {{expected ')'}}
304 struct S1
{ union { int n
; }; S1() : n(n
) {} }; // expected-warning {{field 'n' is uninitialized when used here}}
305 struct S2
{ union { union { int n
; }; char c
; }; S2() : n(n
) {} }; // expected-warning {{field 'n' is uninitialized when used here}}
306 struct S3
{ struct { int n
; }; S3() : n(n
) {} }; // expected-warning {{field 'n' is uninitialized when used here}}
312 B (A
const &); // expected-note 2 {{candidate constructor not viable: no known conversion from 'const PR10758::B' to 'const PR10758::A &' for 1st argument}}
313 B (B
&); // expected-note 2 {{candidate constructor not viable: 1st argument ('const PR10758::B') would lose const qualifier}}
316 A (B
); // expected-note 2 {{passing argument to parameter here}}
320 return b
; // expected-error {{no matching constructor for initialization of 'PR10758::B'}}
324 return b
; // expected-error {{no matching constructor for initialization of 'PR10758::B'}}