1*1c34fb78SRichard Smith // RUN: %clang_cc1 -fsyntax-only -verify -std=c++1y %s
2*1c34fb78SRichard Smith
3*1c34fb78SRichard Smith // expected-no-diagnostics
4b65e8fe1SJohn McCall
5b65e8fe1SJohn McCall // C++11 [basic.link]p6:
6b65e8fe1SJohn McCall // The name of a function declared in block scope and the name
7b65e8fe1SJohn McCall // of a variable declared by a block scope extern declaration
8b65e8fe1SJohn McCall // have linkage. If there is a visible declaration of an entity
9b65e8fe1SJohn McCall // with linkage having the same name and type, ignoring entities
10b65e8fe1SJohn McCall // declared outside the innermost enclosing namespace scope, the
11b65e8fe1SJohn McCall // block scope declaration declares that same entity and
12b65e8fe1SJohn McCall // receives the linkage of the previous declaration.
13b65e8fe1SJohn McCall
14*1c34fb78SRichard Smith extern int same_entity;
get1()15*1c34fb78SRichard Smith constexpr int *get1() {
16*1c34fb78SRichard Smith int same_entity = 0; // not the same entity
17*1c34fb78SRichard Smith {
18*1c34fb78SRichard Smith extern int same_entity;
19*1c34fb78SRichard Smith return &same_entity;
20b65e8fe1SJohn McCall }
21*1c34fb78SRichard Smith }
22*1c34fb78SRichard Smith static_assert(get1() == &same_entity, "failed to find previous decl");
23b65e8fe1SJohn McCall
24*1c34fb78SRichard Smith static int same_entity_2[3];
get2()25*1c34fb78SRichard Smith constexpr int *get2() {
26*1c34fb78SRichard Smith // This is a redeclaration of the same entity, even though it doesn't
27*1c34fb78SRichard Smith // inherit the type of the prior declaration.
28*1c34fb78SRichard Smith extern int same_entity_2[];
29*1c34fb78SRichard Smith return same_entity_2;
30b65e8fe1SJohn McCall }
31*1c34fb78SRichard Smith static_assert(get2() == same_entity_2, "failed to find previous decl");
32b65e8fe1SJohn McCall
33*1c34fb78SRichard Smith static int different_entities;
get3()34*1c34fb78SRichard Smith constexpr int *get3() {
35*1c34fb78SRichard Smith int different_entities = 0;
36*1c34fb78SRichard Smith {
37*1c34fb78SRichard Smith // FIXME: This is not a redeclaration of the prior entity, because
38*1c34fb78SRichard Smith // it is not visible here. Under DR426, this is ill-formed, and without
39*1c34fb78SRichard Smith // it, the static_assert below should fail.
40*1c34fb78SRichard Smith extern int different_entities;
41*1c34fb78SRichard Smith return &different_entities;
42b65e8fe1SJohn McCall }
43b65e8fe1SJohn McCall }
44*1c34fb78SRichard Smith static_assert(get3() == &different_entities, "failed to find previous decl");
45