xref: /minix3/external/bsd/llvm/dist/clang/test/SemaCXX/attr-selectany.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -fms-extensions -fsyntax-only -verify -std=c++11 %s
2f4a2713aSLionel Sambuc // MSVC produces similar diagnostics.
3f4a2713aSLionel Sambuc 
foo()4f4a2713aSLionel Sambuc __declspec(selectany) void foo() { } // expected-error{{'selectany' can only be applied to data items with external linkage}}
5f4a2713aSLionel Sambuc 
6f4a2713aSLionel Sambuc __declspec(selectany) int x1 = 1;
7f4a2713aSLionel Sambuc 
8f4a2713aSLionel Sambuc const __declspec(selectany) int x2 = 2; // expected-error{{'selectany' can only be applied to data items with external linkage}}
9f4a2713aSLionel Sambuc 
10f4a2713aSLionel Sambuc extern const __declspec(selectany) int x3 = 3;
11f4a2713aSLionel Sambuc 
12f4a2713aSLionel Sambuc extern const int x4;
13f4a2713aSLionel Sambuc const __declspec(selectany) int x4 = 4;
14f4a2713aSLionel Sambuc 
15f4a2713aSLionel Sambuc // MSDN says this is incorrect, but MSVC doesn't diagnose it.
16f4a2713aSLionel Sambuc extern __declspec(selectany) int x5;
17f4a2713aSLionel Sambuc 
18f4a2713aSLionel Sambuc static __declspec(selectany) int x6 = 2; // expected-error{{'selectany' can only be applied to data items with external linkage}}
19f4a2713aSLionel Sambuc 
20f4a2713aSLionel Sambuc // FIXME: MSVC accepts this and makes x7 externally visible and comdat, but keep
21f4a2713aSLionel Sambuc // it as internal and not weak/linkonce.
22f4a2713aSLionel Sambuc static int x7; // expected-note{{previous definition}}
23f4a2713aSLionel Sambuc extern __declspec(selectany) int x7;  // expected-warning{{attribute declaration must precede definition}}
24f4a2713aSLionel Sambuc 
asdf()25f4a2713aSLionel Sambuc int asdf() { return x7; }
26f4a2713aSLionel Sambuc 
27f4a2713aSLionel Sambuc class X {
28f4a2713aSLionel Sambuc  public:
X(int i)29f4a2713aSLionel Sambuc   X(int i) { i++; };
30f4a2713aSLionel Sambuc   int i;
31f4a2713aSLionel Sambuc };
32f4a2713aSLionel Sambuc 
33f4a2713aSLionel Sambuc __declspec(selectany) X x(1);
34*0a6a1f1dSLionel Sambuc 
35*0a6a1f1dSLionel Sambuc namespace { class Internal {}; }
36*0a6a1f1dSLionel Sambuc __declspec(selectany) auto x8 = Internal(); // expected-error {{'selectany' can only be applied to data items with external linkage}}
37