Clang Project

clang_source_code/test/CXX/drs/dr11xx.cpp
1// RUN: %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
2// RUN: %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
3// RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
4// RUN: %clang_cc1 -std=c++17 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
5// RUN: %clang_cc1 -std=c++2a %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
6
7namespace dr1113 { // dr1113: partial
8  namespace named {
9    extern int a; // expected-note {{previous}}
10    static int a; // expected-error {{static declaration of 'a' follows non-static}}
11  }
12  namespace {
13    extern int a;
14    static int a; // ok, both declarations have internal linkage
15    int b = a;
16  }
17
18  // FIXME: Per DR1113 and DR4, this is ill-formed due to ambiguity: the second
19  // 'f' has internal linkage, and so does not have C language linkage, so is
20  // not a redeclaration of the first 'f'.
21  //
22  // To avoid a breaking change here, Clang ignores the "internal linkage" effect
23  // of anonymous namespaces on declarations declared within an 'extern "C"'
24  // linkage-specification.
25  extern "C" void f();
26  namespace {
27    extern "C" void f();
28  }
29  void g() { f(); }
30}
31