annotate clang/test/SemaCXX/attr-weak.cpp @ 221:79ff65ed7e25

LLVM12 Original
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 15 Jun 2021 19:15:29 +0900
parents 1d019706d866
children 1f2b6ac9f198
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-pc-linux-gnu -fsyntax-only -verify -std=c++11 %s
anatofuz
parents:
diff changeset
2
anatofuz
parents:
diff changeset
3 static int test0 __attribute__((weak)); // expected-error {{weak declaration cannot have internal linkage}}
anatofuz
parents:
diff changeset
4 static void test1() __attribute__((weak)); // expected-error {{weak declaration cannot have internal linkage}}
anatofuz
parents:
diff changeset
5
anatofuz
parents:
diff changeset
6 namespace test2 __attribute__((weak)) { // expected-warning {{'weak' attribute only applies to variables, functions, and classes}}
anatofuz
parents:
diff changeset
7 }
anatofuz
parents:
diff changeset
8
anatofuz
parents:
diff changeset
9 namespace {
anatofuz
parents:
diff changeset
10 int test3 __attribute__((weak)); // expected-error {{weak declaration cannot have internal linkage}}
anatofuz
parents:
diff changeset
11 void test4() __attribute__((weak)); // expected-error {{weak declaration cannot have internal linkage}}
anatofuz
parents:
diff changeset
12 }
anatofuz
parents:
diff changeset
13
anatofuz
parents:
diff changeset
14 struct Test5 {
anatofuz
parents:
diff changeset
15 static void test5() __attribute__((weak)); // no error
anatofuz
parents:
diff changeset
16 };
anatofuz
parents:
diff changeset
17
anatofuz
parents:
diff changeset
18 namespace {
anatofuz
parents:
diff changeset
19 struct Test6 {
anatofuz
parents:
diff changeset
20 static void test6() __attribute__((weak)); // expected-error {{weak declaration cannot have internal linkage}}
anatofuz
parents:
diff changeset
21 };
anatofuz
parents:
diff changeset
22 }
anatofuz
parents:
diff changeset
23
anatofuz
parents:
diff changeset
24 // GCC rejects the instantiation with the internal type, but some existing
anatofuz
parents:
diff changeset
25 // code expects it. It is also not that different from giving hidden visibility
anatofuz
parents:
diff changeset
26 // to parts of a template that have explicit default visibility, so we accept
anatofuz
parents:
diff changeset
27 // this.
anatofuz
parents:
diff changeset
28 template <class T> struct Test7 {
anatofuz
parents:
diff changeset
29 void test7() __attribute__((weak)) {}
anatofuz
parents:
diff changeset
30 static int var __attribute__((weak));
anatofuz
parents:
diff changeset
31 };
anatofuz
parents:
diff changeset
32 template <class T>
anatofuz
parents:
diff changeset
33 int Test7<T>::var;
anatofuz
parents:
diff changeset
34 namespace { class Internal {}; }
anatofuz
parents:
diff changeset
35 template struct Test7<Internal>;
anatofuz
parents:
diff changeset
36 template struct Test7<int>;
anatofuz
parents:
diff changeset
37
anatofuz
parents:
diff changeset
38 class __attribute__((weak)) Test8 {}; // OK
anatofuz
parents:
diff changeset
39
anatofuz
parents:
diff changeset
40 __attribute__((weak)) auto Test9 = Internal(); // expected-error {{weak declaration cannot have internal linkage}}