Nico Rieck | f8e8b5f | 2014-01-21 23:54:36 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fsyntax-only -verify -std=c++11 %s |
John McCall | 7a198ce | 2011-02-08 22:35:49 +0000 | [diff] [blame] | 2 | |
| 3 | static int test0 __attribute__((weak)); // expected-error {{weak declaration cannot have internal linkage}} |
| 4 | static void test1() __attribute__((weak)); // expected-error {{weak declaration cannot have internal linkage}} |
| 5 | |
Aaron Ballman | adf66b6 | 2017-11-26 20:01:12 +0000 | [diff] [blame] | 6 | namespace test2 __attribute__((weak)) { // expected-warning {{'weak' attribute only applies to variables, functions, and classes}} |
John McCall | 7a198ce | 2011-02-08 22:35:49 +0000 | [diff] [blame] | 7 | } |
| 8 | |
| 9 | namespace { |
| 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 | |
| 14 | struct Test5 { |
| 15 | static void test5() __attribute__((weak)); // no error |
| 16 | }; |
| 17 | |
| 18 | namespace { |
| 19 | struct Test6 { |
| 20 | static void test6() __attribute__((weak)); // expected-error {{weak declaration cannot have internal linkage}} |
| 21 | }; |
| 22 | } |
| 23 | |
Rafael Espindola | f1d2f0e | 2013-01-16 23:11:15 +0000 | [diff] [blame] | 24 | // 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 McCall | 7a198ce | 2011-02-08 22:35:49 +0000 | [diff] [blame] | 28 | template <class T> struct Test7 { |
| 29 | void test7() __attribute__((weak)) {} |
Rafael Espindola | f1d2f0e | 2013-01-16 23:11:15 +0000 | [diff] [blame] | 30 | static int var __attribute__((weak)); |
John McCall | 7a198ce | 2011-02-08 22:35:49 +0000 | [diff] [blame] | 31 | }; |
Rafael Espindola | f1d2f0e | 2013-01-16 23:11:15 +0000 | [diff] [blame] | 32 | template <class T> |
| 33 | int Test7<T>::var; |
Nico Rieck | f8e8b5f | 2014-01-21 23:54:36 +0000 | [diff] [blame] | 34 | namespace { class Internal {}; } |
John McCall | 7a198ce | 2011-02-08 22:35:49 +0000 | [diff] [blame] | 35 | template struct Test7<Internal>; |
| 36 | template struct Test7<int>; |
Aaron Ballman | 604dfec | 2013-12-02 17:07:07 +0000 | [diff] [blame] | 37 | |
| 38 | class __attribute__((weak)) Test8 {}; // OK |
Nico Rieck | f8e8b5f | 2014-01-21 23:54:36 +0000 | [diff] [blame] | 39 | |
| 40 | __attribute__((weak)) auto Test9 = Internal(); // expected-error {{weak declaration cannot have internal linkage}} |