p6.cpp 1.5 KB

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