xref: /minix3/external/bsd/llvm/dist/clang/test/SemaCXX/attr-weakref.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fsyntax-only -verify -std=c++11 %s
2f4a2713aSLionel Sambuc 
3f4a2713aSLionel Sambuc // GCC will accept anything as the argument of weakref. Should we
4f4a2713aSLionel Sambuc // check for an existing decl?
5f4a2713aSLionel Sambuc static int a1() __attribute__((weakref ("foo")));
6f4a2713aSLionel Sambuc static int a2() __attribute__((weakref, alias ("foo")));
7f4a2713aSLionel Sambuc 
8f4a2713aSLionel Sambuc static int a3 __attribute__((weakref ("foo")));
9f4a2713aSLionel Sambuc static int a4 __attribute__((weakref, alias ("foo")));
10f4a2713aSLionel Sambuc 
11f4a2713aSLionel Sambuc // gcc rejects, clang accepts
12f4a2713aSLionel Sambuc static int a5 __attribute__((alias ("foo"), weakref));
13f4a2713aSLionel Sambuc 
14f4a2713aSLionel Sambuc // this is pointless, but accepted by gcc. We reject it.
15f4a2713aSLionel Sambuc static int a6 __attribute__((weakref)); //expected-error {{weakref declaration of 'a6' must also have an alias attribute}}
16f4a2713aSLionel Sambuc 
17f4a2713aSLionel Sambuc // gcc warns, clang rejects
f(void)18f4a2713aSLionel Sambuc void f(void) {
19f4a2713aSLionel Sambuc   static int a __attribute__((weakref ("v2"))); // expected-error {{declaration of 'a' must be in a global context}}
20f4a2713aSLionel Sambuc }
21f4a2713aSLionel Sambuc 
22f4a2713aSLionel Sambuc // both gcc and clang reject
23f4a2713aSLionel Sambuc class c {
24f4a2713aSLionel Sambuc   static int a __attribute__((weakref ("v2"))); // expected-error {{declaration of 'a' must be in a global context}}
25f4a2713aSLionel Sambuc   static int b() __attribute__((weakref ("f3"))); // expected-error {{declaration of 'b' must be in a global context}}
26f4a2713aSLionel Sambuc };
27f4a2713aSLionel Sambuc int a7() __attribute__((weakref ("f1"))); // expected-error {{weakref declaration must have internal linkage}}
28f4a2713aSLionel Sambuc int a8 __attribute__((weakref ("v1"))); // expected-error {{weakref declaration must have internal linkage}}
29f4a2713aSLionel Sambuc 
30f4a2713aSLionel Sambuc // gcc accepts this
31f4a2713aSLionel Sambuc int a9 __attribute__((weakref));  // expected-error {{weakref declaration of 'a9' must also have an alias attribute}}
32f4a2713aSLionel Sambuc 
33f4a2713aSLionel Sambuc static int a10();
34f4a2713aSLionel Sambuc int a10() __attribute__((weakref ("foo")));
35f4a2713aSLionel Sambuc 
36f4a2713aSLionel Sambuc static int v __attribute__((weakref(a1), alias("foo"))); // expected-error {{'weakref' attribute requires a string}}
37*0a6a1f1dSLionel Sambuc 
38*0a6a1f1dSLionel Sambuc __attribute__((weakref ("foo"))) auto a11 = 1; // expected-error {{weakref declaration must have internal linkage}}
39