1 // RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -verify -std=c++11 -Wall %s
4 int n
: 3 = 7; // expected-warning {{C++20 extension}} expected-warning {{changes value from 7 to -1}}
11 int &GetN() { return n
; }
16 struct Recurse
{ // expected-error {{initializer for 'n' needed}}
17 int &n
= // expected-note {{declared here}}
19 Recurse().n
: // expected-note {{in evaluation of exception spec}}
24 int as
[] = { 1, 2, 3 }; // expected-error {{array bound cannot be deduced from a default member initializer}}
25 int bs
[4] = { 4, 5, 6, 7 };
26 int cs
[] = { 8, 9, 10 }; // expected-error {{array bound cannot be deduced from a default member initializer}}
29 template<int n
> struct T
{ static const int B
; };
30 template<> struct T
<2> { template<int C
, int D
> using B
= int; };
31 const int C
= 0, D
= 0;
33 int as
[] = { decltype(x
)::B
<C
, D
>(0) }; // expected-error {{array bound cannot be deduced from a default member initializer}}
34 T
<sizeof(as
) / sizeof(int)> x
;
35 // test that we handle invalid array bound deductions without crashing when the declarator name is itself invalid
36 operator int[](){}; // expected-error {{'operator int' cannot be the name of a variable or data member}} \
37 // expected-error {{array bound cannot be deduced from a default member initializer}}
40 struct ThrowCtor
{ ThrowCtor(int) noexcept(false); };
41 struct NoThrowCtor
{ NoThrowCtor(int) noexcept(true); };
43 struct Throw
{ ThrowCtor tc
= 42; };
44 struct NoThrow
{ NoThrowCtor tc
= 42; };
46 static_assert(!noexcept(Throw()), "incorrect exception specification");
47 static_assert(noexcept(NoThrow()), "incorrect exception specification");
50 CheckExcSpec() noexcept(true) = default;
53 struct CheckExcSpecFail
{
54 CheckExcSpecFail() noexcept(true) = default; // ok, but calls terminate() on exception
59 typedef int A
= 0; // expected-error {{illegal initializer}}
62 // PR10578 / <rdar://problem/9877267>
67 T
* x
= 1; // expected-error{{cannot initialize a variable of type 'int *' with an rvalue of type 'int'}} expected-warning {{unused variable}}
75 Y::Y() try { // expected-note{{in instantiation of member function 'PR10578::X<int>::X' requested here}}
81 struct base
{ ~base() {} };
82 class function
: base
{
83 ~function() {} // expected-note {{implicitly declared private here}}
89 another() : r(thing()) {} // expected-error {{binds to a temporary object}}
90 // expected-error@-1 {{temporary of type 'function' has private destructor}}
91 const function
&r
; // expected-note {{reference member declared here}}
95 namespace rdar14084171
{
96 struct Point
{ // expected-note 3 {{candidate constructor}}
101 Point location
= Point(0,0); // expected-error {{no matching constructor for initialization of 'Point'}}
103 void f(Sprite
& x
) { x
= x
; } // expected-warning {{explicitly assigning value of variable}}
109 template<typename T
= X
,
110 typename U
= decltype(T::m
)>
113 struct Y
{ int b
= f(); };
116 namespace template_valid
{
117 // Valid, we shouldn't build a CXXDefaultInitExpr until A's ctor definition.
120 template <typename T
>
121 struct B
{ int m1
= sizeof(A
) + sizeof(T
); };
127 namespace template_default_ctor
{
129 template <typename T
>
130 struct B
{ // expected-error {{initializer for 'm1' needed}}
131 int m1
= 0; // expected-note {{declared here}}
133 enum { NOE
= noexcept(B
<int>()) }; // expected-note {{in evaluation of exception spec}}
137 namespace default_ctor
{
139 struct B
{ // expected-error {{initializer for 'm1' needed}}
140 int m1
= 0; // expected-note {{declared here}}
142 enum { NOE
= noexcept(B()) }; // expected-note {{in evaluation of exception spec}}
146 namespace member_template
{
148 template <typename T
>
150 struct C
{ // expected-error {{initializer for 'm1' needed}}
151 int m1
= 0; // expected-note {{declared here}}
153 template <typename U
>
154 struct D
{ // expected-error {{initializer for 'm1' needed}}
155 int m1
= 0; // expected-note {{declared here}}
159 NOE1
= noexcept(B
<int>::C()), // expected-note {{in evaluation of exception spec}}
160 NOE2
= noexcept(B
<int>::D
<int>()) // expected-note {{in evaluation of exception spec}}
165 namespace explicit_instantiation
{
166 template<typename T
> struct X
{
167 X(); // expected-note {{in instantiation of default member initializer 'explicit_instantiation::X<float>::n' requested here}}
168 int n
= T::error
; // expected-error {{type 'float' cannot be used prior to '::' because it has no members}}
170 template struct X
<int>; // ok
171 template<typename T
> X
<T
>::X() {}
172 template struct X
<float>; // expected-note {{in instantiation of member function 'explicit_instantiation::X<float>::X' requested here}}
175 namespace local_class
{
176 template<typename T
> void f() {
177 struct X
{ // expected-note {{in instantiation of default member initializer 'local_class::f()::X::n' requested here}}
178 int n
= T::error
; // expected-error {{type 'int' cannot be used prior to '::' because it has no members}}
181 void g() { f
<int>(); } // expected-note {{in instantiation of function template specialization 'local_class::f<int>' requested here}}
187 int x
[3] = {[N
] = 3}; // expected-warning {{C99 extension}}
198 template void foo(int);