1 // RUN: %clang_cc1 -fsyntax-only -verify -Wno-non-c-typedef-for-linkage -std=gnu++11 %s
2 // RUN: %clang_cc1 -fsyntax-only -verify -Wno-non-c-typedef-for-linkage -Wno-c++11-extensions -Wno-local-type-template-args %s -std=gnu++98
3 // RUN: %clang_cc1 -fsyntax-only -verify -Wno-non-c-typedef-for-linkage -Wno-c++11-extensions -Wno-local-type-template-args -fmodules %s
6 int x
; // expected-note {{previous definition is here}}
8 void f() {} // expected-note {{previous definition is here}}
11 extern int x
; // expected-error {{declaration of 'x' has a different language linkage}}
12 extern int y
; // OK, has internal linkage, so no language linkage.
13 void f(); // expected-error {{declaration of 'f' has a different language linkage}}
17 // This is OK. Both test2_f don't have language linkage since they have
20 static void test2_f() {
22 static void test2_f(int x
) {
59 class __attribute__ ((__visibility__("default"))) shared_future
;
62 template <class> friend class shared_future
;
63 shared_future
<_Rp
> share();
65 template <class _Rp
> future
<_Rp
>
68 struct shared_future
<_Rp
&> {
69 shared_future(future
<_Rp
&>&& __f
);
75 shared_future
<int&> f1
= get_future
<int&>();
79 // This is OK. The variables have internal linkage and therefore no language
93 extern "C" { typedef int test7_F(); static test7_F test7_f
; }
94 extern "C++" { extern test7_F test7_f
; }
96 // FIXME: This should be invalid. The function has no language linkage, but
97 // the function type has, so this is redeclaring the function with a different
100 static void test8_f();
103 extern void test8_f();
106 static void test8_g();
109 extern void test8_g();
113 void __attribute__((overloadable
)) test9_f(int c
); // expected-note {{previous declaration is here}}
116 void __attribute__((overloadable
)) test9_f(int c
); // expected-error {{declaration of 'test9_f' has a different language linkage}}
120 void __attribute__((overloadable
)) test10_f(int);
121 void __attribute__((overloadable
)) test10_f(double);
126 void __attribute__((overloadable
)) test11_g(int);
127 void __attribute__((overloadable
)) test11_g(double);
142 static void a(void) {}
146 // Anonymous namespace implies internal linkage, so 'static' has no effect.
149 static void a(void) {}
154 const int a
= 5; // expected-note {{previous definition is here}}
155 static const int a
; // expected-error {{redefinition of 'a'}}
162 friend int bar(Foo
*y
);
175 template <typename T1
, typename T2
> void foo() {}
176 template <typename T
, T x
> void bar() {} // expected-note {{candidate function}}
180 // foo<L, I>'s linkage should be the merge of UniqueExternalLinkage (or
181 // InternalLinkage in c++11) and VisibleNoLinkage. The correct answer is
182 // NoLinkage in both cases. This means that using foo<L, I> as a template
183 // argument should fail.
184 return reinterpret_cast<void*>(bar
<typeof(foo
<L
, I
>), foo
<L
, I
> >); // expected-error {{reinterpret_cast cannot resolve overloaded function 'bar' to type 'void *}}
192 template <typename T
> struct foo
{
193 template <T
*P
> static void f() {}
194 static void *g() { return (void *)f
<&x
>; }
197 template <typename T
> T foo
<T
>::x
;
203 void *h() { return f(); }
206 extern "C" void pr16247_foo(int);
207 static void pr16247_foo(double);
208 void pr16247_foo(int) {}
209 void pr16247_foo(double) {}
212 extern "C" void pr16247_bar(int);
213 static void pr16247_bar(double);
214 void pr16247_bar(int) {}
215 void pr16247_bar(double) {}
218 unsigned &*foo
; //expected-error{{'foo' declared as a pointer to a reference of type}}
219 extern struct {} *foo
; // don't assert
222 namespace typedef_name_for_linkage
{
223 template<typename T
> struct Use
{};
225 struct A
{ A(); A(const A
&); ~A(); };
238 void f() { static int n
; struct Inner
{};}
241 // FIXME: Ideally this would be accepted in all modes. In C++98, we trigger a
242 // linkage calculation to drive the "internal linkage type as template
243 // argument" warning.
245 void f() { struct Inner
{}; Use
<Inner
> ui
; }
247 #if __cplusplus < 201103L
248 // expected-error@-4 {{given name for linkage purposes by typedef declaration after its linkage was computed}}
249 // expected-note@-4 {{due to this member}}
250 // expected-note@-4 {{by this typedef}}