1dd9459f8869f66409f7ea429053b453e33f6499cRichard Smith// RUN: %clang_cc1 -fsyntax-only -verify -std=c++1y %s 2dd9459f8869f66409f7ea429053b453e33f6499cRichard Smith 3dd9459f8869f66409f7ea429053b453e33f6499cRichard Smith// expected-no-diagnostics 45b8740f840238b3616691e5b300df57a758f32a6John McCall 55b8740f840238b3616691e5b300df57a758f32a6John McCall// C++11 [basic.link]p6: 65b8740f840238b3616691e5b300df57a758f32a6John McCall// The name of a function declared in block scope and the name 75b8740f840238b3616691e5b300df57a758f32a6John McCall// of a variable declared by a block scope extern declaration 85b8740f840238b3616691e5b300df57a758f32a6John McCall// have linkage. If there is a visible declaration of an entity 95b8740f840238b3616691e5b300df57a758f32a6John McCall// with linkage having the same name and type, ignoring entities 105b8740f840238b3616691e5b300df57a758f32a6John McCall// declared outside the innermost enclosing namespace scope, the 115b8740f840238b3616691e5b300df57a758f32a6John McCall// block scope declaration declares that same entity and 125b8740f840238b3616691e5b300df57a758f32a6John McCall// receives the linkage of the previous declaration. 135b8740f840238b3616691e5b300df57a758f32a6John McCall 14dd9459f8869f66409f7ea429053b453e33f6499cRichard Smithextern int same_entity; 15dd9459f8869f66409f7ea429053b453e33f6499cRichard Smithconstexpr int *get1() { 16dd9459f8869f66409f7ea429053b453e33f6499cRichard Smith int same_entity = 0; // not the same entity 17dd9459f8869f66409f7ea429053b453e33f6499cRichard Smith { 18dd9459f8869f66409f7ea429053b453e33f6499cRichard Smith extern int same_entity; 19dd9459f8869f66409f7ea429053b453e33f6499cRichard Smith return &same_entity; 205b8740f840238b3616691e5b300df57a758f32a6John McCall } 215b8740f840238b3616691e5b300df57a758f32a6John McCall} 22dd9459f8869f66409f7ea429053b453e33f6499cRichard Smithstatic_assert(get1() == &same_entity, "failed to find previous decl"); 235b8740f840238b3616691e5b300df57a758f32a6John McCall 24dd9459f8869f66409f7ea429053b453e33f6499cRichard Smithstatic int same_entity_2[3]; 25dd9459f8869f66409f7ea429053b453e33f6499cRichard Smithconstexpr int *get2() { 26dd9459f8869f66409f7ea429053b453e33f6499cRichard Smith // This is a redeclaration of the same entity, even though it doesn't 27dd9459f8869f66409f7ea429053b453e33f6499cRichard Smith // inherit the type of the prior declaration. 28dd9459f8869f66409f7ea429053b453e33f6499cRichard Smith extern int same_entity_2[]; 29dd9459f8869f66409f7ea429053b453e33f6499cRichard Smith return same_entity_2; 305b8740f840238b3616691e5b300df57a758f32a6John McCall} 31dd9459f8869f66409f7ea429053b453e33f6499cRichard Smithstatic_assert(get2() == same_entity_2, "failed to find previous decl"); 325b8740f840238b3616691e5b300df57a758f32a6John McCall 33dd9459f8869f66409f7ea429053b453e33f6499cRichard Smithstatic int different_entities; 34dd9459f8869f66409f7ea429053b453e33f6499cRichard Smithconstexpr int *get3() { 35dd9459f8869f66409f7ea429053b453e33f6499cRichard Smith int different_entities = 0; 36dd9459f8869f66409f7ea429053b453e33f6499cRichard Smith { 37dd9459f8869f66409f7ea429053b453e33f6499cRichard Smith // FIXME: This is not a redeclaration of the prior entity, because 38dd9459f8869f66409f7ea429053b453e33f6499cRichard Smith // it is not visible here. Under DR426, this is ill-formed, and without 39dd9459f8869f66409f7ea429053b453e33f6499cRichard Smith // it, the static_assert below should fail. 40dd9459f8869f66409f7ea429053b453e33f6499cRichard Smith extern int different_entities; 41dd9459f8869f66409f7ea429053b453e33f6499cRichard Smith return &different_entities; 425b8740f840238b3616691e5b300df57a758f32a6John McCall } 435b8740f840238b3616691e5b300df57a758f32a6John McCall} 44dd9459f8869f66409f7ea429053b453e33f6499cRichard Smithstatic_assert(get3() == &different_entities, "failed to find previous decl"); 45