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