blob: 3cfa98138babb3e4e0875cbadfd4617524d05b6d [file] [log] [blame]
Rafael Espindolae57e3d32012-12-27 03:56:20 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Richard Smithd613ac92013-04-04 01:51:11 +00002// RUN: %clang_cc1 -fsyntax-only -verify -fmodules %s
Rafael Espindolae57e3d32012-12-27 03:56:20 +00003
4namespace test1 {
5 int x; // expected-note {{previous definition is here}}
Rafael Espindola950fee22013-02-14 01:18:37 +00006 static int y;
Rafael Espindolae57e3d32012-12-27 03:56:20 +00007 void f() {} // expected-note {{previous definition is here}}
8
9 extern "C" {
10 extern int x; // expected-error {{declaration of 'x' has a different language linkage}}
Rafael Espindola950fee22013-02-14 01:18:37 +000011 extern int y; // OK, has internal linkage, so no language linkage.
Rafael Espindolae57e3d32012-12-27 03:56:20 +000012 void f(); // expected-error {{declaration of 'f' has a different language linkage}}
13 }
14}
Rafael Espindola78eeba82012-12-28 14:21:58 +000015
Rafael Espindola02fb50d2013-02-23 00:26:28 +000016// This is OK. Both test2_f don't have language linkage since they have
17// internal linkage.
Rafael Espindola78eeba82012-12-28 14:21:58 +000018extern "C" {
Rafael Espindola02fb50d2013-02-23 00:26:28 +000019 static void test2_f() {
Rafael Espindola78eeba82012-12-28 14:21:58 +000020 }
Rafael Espindola02fb50d2013-02-23 00:26:28 +000021 static void test2_f(int x) {
Rafael Espindola78eeba82012-12-28 14:21:58 +000022 }
23}
Rafael Espindola6acc4bc2013-01-05 01:28:37 +000024
25namespace test3 {
26 extern "C" {
27 namespace {
28 extern int x2;
29 void f2();
30 }
31 }
32 namespace {
33 int x2;
34 void f2() {}
35 }
36}
37
38namespace test4 {
39 void dummy() {
40 void Bar();
41 class A {
42 friend void Bar();
43 };
44 }
45}
Rafael Espindolaabe75ef2013-01-09 16:34:58 +000046
47namespace test5 {
48 static void g();
49 void f()
50 {
51 void g();
52 }
53}
Rafael Espindola013539c2013-01-12 01:01:06 +000054
55// pr14898
56namespace test6 {
57 template <class _Rp>
58 class __attribute__ ((__visibility__("default"))) shared_future;
59 template <class _Rp>
60 class future {
61 template <class> friend class shared_future;
62 shared_future<_Rp> share();
63 };
64 template <class _Rp> future<_Rp>
65 get_future();
66 template <class _Rp>
67 struct shared_future<_Rp&> {
68 shared_future(future<_Rp&>&& __f); // expected-warning {{rvalue references are a C++11 extension}}
69 };
70 void f() {
71 typedef int T;
72 get_future<int>();
73 typedef int& U;
74 shared_future<int&> f1 = get_future<int&>();
75 }
76}
Rafael Espindola950fee22013-02-14 01:18:37 +000077
78// This is OK. The variables have internal linkage and therefore no language
79// linkage.
80extern "C" {
81 static int test7_x;
82}
83extern "C++" {
84 extern int test7_x;
85}
86extern "C++" {
87 static int test7_y;
88}
89extern "C" {
90 extern int test7_y;
91}
92extern "C" { typedef int test7_F(); static test7_F test7_f; }
93extern "C++" { extern test7_F test7_f; }
94
95// FIXME: This should be invalid. The function has no language linkage, but
96// the function type has, so this is redeclaring the function with a different
97// type.
98extern "C++" {
99 static void test8_f();
100}
101extern "C" {
102 extern void test8_f();
103}
104extern "C" {
105 static void test8_g();
106}
107extern "C++" {
108 extern void test8_g();
109}
Rafael Espindolad2fdd422013-02-14 01:47:04 +0000110
111extern "C" {
112 void __attribute__((overloadable)) test9_f(int c); // expected-note {{previous declaration is here}}
113}
114extern "C++" {
115 void __attribute__((overloadable)) test9_f(int c); // expected-error {{declaration of 'test9_f' has a different language linkage}}
116}
117
118extern "C" {
119 void __attribute__((overloadable)) test10_f(int);
120 void __attribute__((overloadable)) test10_f(double);
121}
122
123extern "C" {
124 void test11_f() {
125 void __attribute__((overloadable)) test11_g(int);
126 void __attribute__((overloadable)) test11_g(double);
127 }
128}
Rafael Espindola80a86892013-04-04 02:47:57 +0000129
130namespace test12 {
131 const int n = 0;
132 extern const int n;
133 void f() {
134 extern const int n;
135 }
136}
Rafael Espindolaba2bfa02013-04-04 16:43:41 +0000137
138namespace test13 {
139 static void a(void);
140 extern void a();
141 static void a(void) {}
142}
Rafael Espindola29c41b52013-04-04 17:16:12 +0000143
144namespace test14 {
145 namespace {
146 void a(void); // expected-note {{previous declaration is here}}
147 static void a(void) {} // expected-error {{static declaration of 'a' follows non-static declaration}}
148 }
149}
Rafael Espindolaea4b1112013-04-04 21:21:25 +0000150
151namespace test15 {
152 const int a = 5; // expected-note {{previous definition is here}}
153 static const int a; // expected-error {{redefinition of 'a'}}
154}
Rafael Espindola11dc6342013-04-25 20:12:36 +0000155
156namespace test16 {
157 extern "C" {
158 class Foo {
159 int x;
160 friend int bar(Foo *y);
161 };
162 int bar(Foo *y) {
163 return y->x;
164 }
165 }
166}