1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fsyntax-only -verify -std=c++11 %s 2f4a2713aSLionel Sambuc 3f4a2713aSLionel Sambuc static int test0 __attribute__((weak)); // expected-error {{weak declaration cannot have internal linkage}} 4f4a2713aSLionel Sambuc static void test1() __attribute__((weak)); // expected-error {{weak declaration cannot have internal linkage}} 5f4a2713aSLionel Sambuc 6*0a6a1f1dSLionel Sambuc namespace test2 __attribute__((weak)) { // expected-warning {{'weak' attribute only applies to variables, functions and classes}} 7f4a2713aSLionel Sambuc } 8f4a2713aSLionel Sambuc 9f4a2713aSLionel Sambuc namespace { 10f4a2713aSLionel Sambuc int test3 __attribute__((weak)); // expected-error {{weak declaration cannot have internal linkage}} 11f4a2713aSLionel Sambuc void test4() __attribute__((weak)); // expected-error {{weak declaration cannot have internal linkage}} 12f4a2713aSLionel Sambuc } 13f4a2713aSLionel Sambuc 14f4a2713aSLionel Sambuc struct Test5 { 15f4a2713aSLionel Sambuc static void test5() __attribute__((weak)); // no error 16f4a2713aSLionel Sambuc }; 17f4a2713aSLionel Sambuc 18f4a2713aSLionel Sambuc namespace { 19f4a2713aSLionel Sambuc struct Test6 { 20f4a2713aSLionel Sambuc static void test6() __attribute__((weak)); // expected-error {{weak declaration cannot have internal linkage}} 21f4a2713aSLionel Sambuc }; 22f4a2713aSLionel Sambuc } 23f4a2713aSLionel Sambuc 24f4a2713aSLionel Sambuc // GCC rejects the instantiation with the internal type, but some existing 25f4a2713aSLionel Sambuc // code expects it. It is also not that different from giving hidden visibility 26f4a2713aSLionel Sambuc // to parts of a template that have explicit default visibility, so we accept 27f4a2713aSLionel Sambuc // this. 28f4a2713aSLionel Sambuc template <class T> struct Test7 { test7Test729f4a2713aSLionel Sambuc void test7() __attribute__((weak)) {} 30f4a2713aSLionel Sambuc static int var __attribute__((weak)); 31f4a2713aSLionel Sambuc }; 32f4a2713aSLionel Sambuc template <class T> 33f4a2713aSLionel Sambuc int Test7<T>::var; 34*0a6a1f1dSLionel Sambuc namespace { class Internal {}; } 35f4a2713aSLionel Sambuc template struct Test7<Internal>; 36f4a2713aSLionel Sambuc template struct Test7<int>; 37*0a6a1f1dSLionel Sambuc 38*0a6a1f1dSLionel Sambuc class __attribute__((weak)) Test8 {}; // OK 39*0a6a1f1dSLionel Sambuc 40*0a6a1f1dSLionel Sambuc __attribute__((weak)) auto Test9 = Internal(); // expected-error {{weak declaration cannot have internal linkage}} 41