p6.cpp revision 5b8740f840238b3616691e5b300df57a758f32a6
15b8740f840238b3616691e5b300df57a758f32a6John McCall// RUN: %clang_cc1 -fsyntax-only -verify %s
25b8740f840238b3616691e5b300df57a758f32a6John McCall
35b8740f840238b3616691e5b300df57a758f32a6John McCall// C++11 [basic.link]p6:
45b8740f840238b3616691e5b300df57a758f32a6John McCall//   The name of a function declared in block scope and the name
55b8740f840238b3616691e5b300df57a758f32a6John McCall//   of a variable declared by a block scope extern declaration
65b8740f840238b3616691e5b300df57a758f32a6John McCall//   have linkage. If there is a visible declaration of an entity
75b8740f840238b3616691e5b300df57a758f32a6John McCall//   with linkage having the same name and type, ignoring entities
85b8740f840238b3616691e5b300df57a758f32a6John McCall//   declared outside the innermost enclosing namespace scope, the
95b8740f840238b3616691e5b300df57a758f32a6John McCall//   block scope declaration declares that same entity and
105b8740f840238b3616691e5b300df57a758f32a6John McCall//   receives the linkage of the previous declaration.
115b8740f840238b3616691e5b300df57a758f32a6John McCall
125b8740f840238b3616691e5b300df57a758f32a6John McCall// rdar://13535367
135b8740f840238b3616691e5b300df57a758f32a6John McCallnamespace test0 {
145b8740f840238b3616691e5b300df57a758f32a6John McCall  extern "C" int test0_array[];
155b8740f840238b3616691e5b300df57a758f32a6John McCall  void declare() { extern int test0_array[100]; }
165b8740f840238b3616691e5b300df57a758f32a6John McCall  extern "C" int test0_array[];
175b8740f840238b3616691e5b300df57a758f32a6John McCall  int value = sizeof(test0_array); // expected-error {{invalid application of 'sizeof' to an incomplete type 'int []'}}
185b8740f840238b3616691e5b300df57a758f32a6John McCall}
195b8740f840238b3616691e5b300df57a758f32a6John McCall
205b8740f840238b3616691e5b300df57a758f32a6John McCallnamespace test1 {
215b8740f840238b3616691e5b300df57a758f32a6John McCall  extern "C" int test1_array[];
225b8740f840238b3616691e5b300df57a758f32a6John McCall  void test() {
235b8740f840238b3616691e5b300df57a758f32a6John McCall    { extern int test1_array[100]; }
245b8740f840238b3616691e5b300df57a758f32a6John McCall    extern int test1_array[];
255b8740f840238b3616691e5b300df57a758f32a6John McCall    int x = sizeof(test1_array); // expected-error {{invalid application of 'sizeof' to an incomplete type 'int []'}}
265b8740f840238b3616691e5b300df57a758f32a6John McCall  }
275b8740f840238b3616691e5b300df57a758f32a6John McCall}
285b8740f840238b3616691e5b300df57a758f32a6John McCall
295b8740f840238b3616691e5b300df57a758f32a6John McCallnamespace test2 {
305b8740f840238b3616691e5b300df57a758f32a6John McCall  void declare() { extern int test2_array[100]; }
315b8740f840238b3616691e5b300df57a758f32a6John McCall  extern int test2_array[];
325b8740f840238b3616691e5b300df57a758f32a6John McCall  int value = sizeof(test2_array); // expected-error {{invalid application of 'sizeof' to an incomplete type 'int []'}}
335b8740f840238b3616691e5b300df57a758f32a6John McCall}
345b8740f840238b3616691e5b300df57a758f32a6John McCall
355b8740f840238b3616691e5b300df57a758f32a6John McCallnamespace test3 {
365b8740f840238b3616691e5b300df57a758f32a6John McCall  void test() {
375b8740f840238b3616691e5b300df57a758f32a6John McCall    { extern int test3_array[100]; }
385b8740f840238b3616691e5b300df57a758f32a6John McCall    extern int test3_array[];
395b8740f840238b3616691e5b300df57a758f32a6John McCall    int x = sizeof(test3_array); // expected-error {{invalid application of 'sizeof' to an incomplete type 'int []'}}
405b8740f840238b3616691e5b300df57a758f32a6John McCall  }
415b8740f840238b3616691e5b300df57a758f32a6John McCall}
425b8740f840238b3616691e5b300df57a758f32a6John McCall
435b8740f840238b3616691e5b300df57a758f32a6John McCall
44