blob: 51deb664ce6ea635d4aefe1221507dc8b76e2b6f [file] [log] [blame]
Nico Rieckf8e8b5f2014-01-21 23:54:36 +00001// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fsyntax-only -verify -std=c++11 %s
John McCall7a198ce2011-02-08 22:35:49 +00002
3static int test0 __attribute__((weak)); // expected-error {{weak declaration cannot have internal linkage}}
4static void test1() __attribute__((weak)); // expected-error {{weak declaration cannot have internal linkage}}
5
Aaron Ballmanadf66b62017-11-26 20:01:12 +00006namespace test2 __attribute__((weak)) { // expected-warning {{'weak' attribute only applies to variables, functions, and classes}}
John McCall7a198ce2011-02-08 22:35:49 +00007}
8
9namespace {
10 int test3 __attribute__((weak)); // expected-error {{weak declaration cannot have internal linkage}}
11 void test4() __attribute__((weak)); // expected-error {{weak declaration cannot have internal linkage}}
12}
13
14struct Test5 {
15 static void test5() __attribute__((weak)); // no error
16};
17
18namespace {
19 struct Test6 {
20 static void test6() __attribute__((weak)); // expected-error {{weak declaration cannot have internal linkage}}
21 };
22}
23
Rafael Espindolaf1d2f0e2013-01-16 23:11:15 +000024// GCC rejects the instantiation with the internal type, but some existing
25// code expects it. It is also not that different from giving hidden visibility
26// to parts of a template that have explicit default visibility, so we accept
27// this.
John McCall7a198ce2011-02-08 22:35:49 +000028template <class T> struct Test7 {
29 void test7() __attribute__((weak)) {}
Rafael Espindolaf1d2f0e2013-01-16 23:11:15 +000030 static int var __attribute__((weak));
John McCall7a198ce2011-02-08 22:35:49 +000031};
Rafael Espindolaf1d2f0e2013-01-16 23:11:15 +000032template <class T>
33int Test7<T>::var;
Nico Rieckf8e8b5f2014-01-21 23:54:36 +000034namespace { class Internal {}; }
John McCall7a198ce2011-02-08 22:35:49 +000035template struct Test7<Internal>;
36template struct Test7<int>;
Aaron Ballman604dfec2013-12-02 17:07:07 +000037
38class __attribute__((weak)) Test8 {}; // OK
Nico Rieckf8e8b5f2014-01-21 23:54:36 +000039
40__attribute__((weak)) auto Test9 = Internal(); // expected-error {{weak declaration cannot have internal linkage}}