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