Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CXX / basic / basic.link / p6.cpp
blobac6dc2f1f1a394dd2e8c867bd6cbc9ebed3e75dc
1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++1y %s
3 // expected-no-diagnostics
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.
14 extern int same_entity;
15 constexpr int *get1() {
16 int same_entity = 0; // not the same entity
18 extern int same_entity;
19 return &same_entity;
22 static_assert(get1() == &same_entity, "failed to find previous decl");
24 static int same_entity_2[3];
25 constexpr 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;
31 static_assert(get2() == same_entity_2, "failed to find previous decl");
33 static int different_entities;
34 constexpr int *get3() {
35 int different_entities = 0;
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;
44 static_assert(get3() == &different_entities, "failed to find previous decl");