1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++1y -triple x86_64-linux-gnu %s
3 // If there is a preceding declaration of the entity *in the same scope* in
4 // which the bound was specified, an omitted array bound is taken to be the
5 // same as in that earlier declaration
8 extern "C" int array
[];
9 void declare() { extern int array
[100]; }
10 int value1
= sizeof(array
); // expected-error {{invalid application of 'sizeof' to an incomplete type 'int[]'}}
11 extern "C" int array
[];
12 int value2
= sizeof(array
); // expected-error {{invalid application of 'sizeof' to an incomplete type 'int[]'}}
16 extern "C" int array
[];
18 { extern int array
[100]; }
20 int x
= sizeof(array
); // expected-error {{invalid application of 'sizeof' to an incomplete type 'int[]'}}
25 void declare() { extern int array
[100]; }
27 int value
= sizeof(array
); // expected-error {{invalid application of 'sizeof' to an incomplete type 'int[]'}}
32 { extern int array
[100]; }
34 int x
= sizeof(array
); // expected-error {{invalid application of 'sizeof' to an incomplete type 'int[]'}}
41 extern int array
[100];
42 int x
= sizeof(array
);
44 int y
= sizeof(array
); // expected-error {{invalid application of 'sizeof' to an incomplete type 'int[]'}}
49 extern int array
[100];
51 int x
= sizeof(array
);
57 extern int array
[100];
60 int x
= sizeof(array
); // expected-error {{invalid application of 'sizeof' to an incomplete type 'int[]'}}
62 int y
= sizeof(array
);
64 int z
= sizeof(array
);
69 extern int array
[100];
72 int x
= sizeof(array
); // expected-error {{invalid application of 'sizeof' to an incomplete type 'int[]'}}
74 int y
= sizeof(array
);
76 int z
= sizeof(array
);
82 extern int array
[100];
83 int x
= sizeof(array
);
85 int y
= sizeof(array
); // expected-error {{invalid application of 'sizeof' to an incomplete type 'int[]'}}
87 int z
= sizeof(array
); // expected-error {{invalid application of 'sizeof' to an incomplete type 'int[]'}}
91 template<typename T
> void f() {
96 static_assert(sizeof(arr1
) == 12, "");
97 static_assert(sizeof(arr2
) == 12, "");
99 // Use a failing test to ensure the type isn't considered dependent.
100 static_assert(sizeof(arr2
) == 13, ""); // expected-error {{failed}} \
101 // expected-note {{evaluates to '12 == 13'}}
104 void g() { f
<int[3]>(); } // expected-note {{in instantiation of}}
106 template<typename T
> void h1() {
112 // Detected in template definition.
113 (void)sizeof(arr3
); // expected-error {{incomplete}}
118 template<typename T
> void h2() {
124 // Detected in template instantiation.
125 (void)sizeof(arr4
); // expected-error {{incomplete}}
132 h2
<int[]>(); // expected-note {{in instantiation of}}
136 template<typename T
> void j() {
139 (void)sizeof(arr5
); // expected-error {{incomplete}}
140 (void)sizeof(arr6
); // expected-error {{incomplete}}
144 void k() { j
<int[]>(); } // expected-note {{in instantiation of}}
146 template<typename T
, typename U
> void l() {
147 extern T arrX
; // expected-note {{previous}}
148 extern U arrX
; // expected-error {{different type: 'int[4]' vs 'int[3]'}}
149 (void)sizeof(arrX
); // expected-error {{incomplete}}
153 l
<int[], int[3]>(); // ok
154 l
<int[3], int[]>(); // ok
155 l
<int[3], int[3]>(); // ok
156 l
<int[3], int[4]>(); // expected-note {{in instantiation of}}
157 l
<int[], int[]>(); // expected-note {{in instantiation of}}
160 template<typename T
> void n() {
161 extern T n_var
; // expected-error {{redeclaration of 'n_var' with a different type: 'double' vs 'int'}} expected-note {{previous}}
162 extern T
n_fn(); // expected-error {{functions that differ only in their return type cannot be overloaded}} expected-note {{previous}}
164 template void n
<int>();
165 template void n
<double>(); // expected-note {{in instantiation of}}
167 template<typename T
> void o() {
168 extern T o_var
; // expected-note {{previous}}
169 extern T
o_fn(); // expected-note {{previous}}
171 template void o
<int>();
172 float o_var
; // expected-error {{redefinition of 'o_var' with a different type: 'float' vs 'int'}}
173 float o_fn(); // expected-error {{functions that differ only in their return type cannot be overloaded}}
177 template<typename T
> void p() {
183 namespace use_outside_ns
{
192 template<typename T
> void x() {
197 template void x
<int[]>();
199 int w
= sizeof(A::a
);
200 int x
= sizeof(A::b
); // expected-error {{incomplete}}
201 int y
= sizeof(A::c
);
202 int z
= sizeof(A::d
);
204 int g() { return sizeof(a
); }
205 int h() { return sizeof(b
); } // expected-error {{incomplete}}
206 int i() { return sizeof(c
); }
207 int j() { return sizeof(d
); }
212 void f1() { extern int arr
[2]; } // expected-note {{previous}}
213 void f2() { extern int arr
[3]; } // expected-error {{different type: 'int[3]' vs 'int[2]'}}