annotate clang/test/SemaCXX/attr-selectany.cpp @ 222:81f6424ef0e3 llvm-original

LLVM original branch
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 18 Jul 2021 22:10:01 +0900
parents 1d019706d866
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -triple x86_64-win32 -fms-compatibility -fms-extensions -fsyntax-only -verify -std=c++11 %s
anatofuz
parents:
diff changeset
2 // RUN: %clang_cc1 -triple x86_64-unknown-linux -fms-compatibility -fms-extensions -fsyntax-only -verify -std=c++11 %s
anatofuz
parents:
diff changeset
3 // RUN: %clang_cc1 -triple x86_64-win32-macho -fms-compatibility -fms-extensions -fsyntax-only -verify -std=c++11 %s
anatofuz
parents:
diff changeset
4
anatofuz
parents:
diff changeset
5 // MSVC produces similar diagnostics.
anatofuz
parents:
diff changeset
6
anatofuz
parents:
diff changeset
7 __declspec(selectany) void foo() { } // expected-error{{'selectany' can only be applied to data items with external linkage}}
anatofuz
parents:
diff changeset
8
anatofuz
parents:
diff changeset
9 __declspec(selectany) int x1 = 1;
anatofuz
parents:
diff changeset
10
anatofuz
parents:
diff changeset
11 const __declspec(selectany) int x2 = 2; // expected-error{{'selectany' can only be applied to data items with external linkage}}
anatofuz
parents:
diff changeset
12
anatofuz
parents:
diff changeset
13 extern const __declspec(selectany) int x3 = 3;
anatofuz
parents:
diff changeset
14
anatofuz
parents:
diff changeset
15 extern const int x4;
anatofuz
parents:
diff changeset
16 const __declspec(selectany) int x4 = 4;
anatofuz
parents:
diff changeset
17
anatofuz
parents:
diff changeset
18 // MSDN says this is incorrect, but MSVC doesn't diagnose it.
anatofuz
parents:
diff changeset
19 extern __declspec(selectany) int x5;
anatofuz
parents:
diff changeset
20
anatofuz
parents:
diff changeset
21 static __declspec(selectany) int x6 = 2; // expected-error{{'selectany' can only be applied to data items with external linkage}}
anatofuz
parents:
diff changeset
22
anatofuz
parents:
diff changeset
23 // FIXME: MSVC accepts this and makes x7 externally visible and comdat, but keep
anatofuz
parents:
diff changeset
24 // it as internal and not weak/linkonce.
anatofuz
parents:
diff changeset
25 static int x7; // expected-note{{previous definition}}
anatofuz
parents:
diff changeset
26 extern __declspec(selectany) int x7; // expected-warning{{attribute declaration must precede definition}}
anatofuz
parents:
diff changeset
27
anatofuz
parents:
diff changeset
28 int asdf() { return x7; }
anatofuz
parents:
diff changeset
29
anatofuz
parents:
diff changeset
30 class X {
anatofuz
parents:
diff changeset
31 public:
anatofuz
parents:
diff changeset
32 X(int i) { i++; };
anatofuz
parents:
diff changeset
33 int i;
anatofuz
parents:
diff changeset
34 };
anatofuz
parents:
diff changeset
35
anatofuz
parents:
diff changeset
36 __declspec(selectany) X x(1);
anatofuz
parents:
diff changeset
37
anatofuz
parents:
diff changeset
38 namespace { class Internal {}; }
anatofuz
parents:
diff changeset
39 __declspec(selectany) auto x8 = Internal(); // expected-error {{'selectany' can only be applied to data items with external linkage}}
anatofuz
parents:
diff changeset
40
anatofuz
parents:
diff changeset
41
anatofuz
parents:
diff changeset
42 // The D3D11 headers do something like this. MSVC doesn't error on this at
anatofuz
parents:
diff changeset
43 // all, even without the __declspec(selectany), in violation of the standard.
anatofuz
parents:
diff changeset
44 // We fall back to a warning for selectany to accept headers.
anatofuz
parents:
diff changeset
45 struct SomeStruct {
anatofuz
parents:
diff changeset
46 int foo;
anatofuz
parents:
diff changeset
47 };
anatofuz
parents:
diff changeset
48 extern const __declspec(selectany) SomeStruct some_struct; // expected-warning {{default initialization of an object of const type 'const SomeStruct' without a user-provided default constructor is a Microsoft extension}}
anatofuz
parents:
diff changeset
49
anatofuz
parents:
diff changeset
50 // It should be possible to redeclare variables that were defined
anatofuz
parents:
diff changeset
51 // __declspec(selectany) previously.
anatofuz
parents:
diff changeset
52 extern const SomeStruct some_struct;
anatofuz
parents:
diff changeset
53
anatofuz
parents:
diff changeset
54 // Without selectany, this should stay an error.
anatofuz
parents:
diff changeset
55 const SomeStruct some_struct2; // expected-error {{default initialization of an object of const type 'const SomeStruct' without a user-provided default constructor}}