brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.5 KiB · ac6dc2f Raw
45 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify -std=c++1y %s2 3// expected-no-diagnostics4 5// C++11 [basic.link]p6:6//   The name of a function declared in block scope and the name7//   of a variable declared by a block scope extern declaration8//   have linkage. If there is a visible declaration of an entity9//   with linkage having the same name and type, ignoring entities10//   declared outside the innermost enclosing namespace scope, the11//   block scope declaration declares that same entity and12//   receives the linkage of the previous declaration.13 14extern int same_entity;15constexpr int *get1() {16  int same_entity = 0; // not the same entity17  {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't27  // 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, because38    // it is not visible here. Under DR426, this is ill-formed, and without39    // 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