linkage2.cpp revision 747836e5c79b5e12fe9cfb9b724dc4edeb115419
1// RUN: %clang_cc1 -fsyntax-only -verify %s
2
3namespace test1 {
4  int x; // expected-note {{previous definition is here}}
5  static int y;
6  void f() {} // expected-note {{previous definition is here}}
7
8  extern "C" {
9    extern int x; // expected-error {{declaration of 'x' has a different language linkage}}
10    extern int y; // OK, has internal linkage, so no language linkage.
11    void f(); // expected-error {{declaration of 'f' has a different language linkage}}
12  }
13}
14
15// FIXME: This should be OK. Both test2_f don't have language linkage since they
16// have internal linkage.
17extern "C" {
18  static void test2_f() { // expected-note {{previous definition is here}}
19  }
20  static void test2_f(int x) { // expected-error {{conflicting types for 'test2_f'}}
21  }
22}
23
24namespace test3 {
25  extern "C" {
26    namespace {
27      extern int x2;
28      void f2();
29    }
30  }
31  namespace {
32    int x2;
33    void f2() {}
34  }
35}
36
37namespace test4 {
38  void dummy() {
39    void Bar();
40    class A {
41      friend void Bar();
42    };
43  }
44}
45
46namespace test5 {
47  static void g();
48  void f()
49  {
50    void g();
51  }
52}
53
54// pr14898
55namespace test6 {
56  template <class _Rp>
57  class __attribute__ ((__visibility__("default"))) shared_future;
58  template <class _Rp>
59  class future {
60    template <class> friend class shared_future;
61    shared_future<_Rp> share();
62  };
63  template <class _Rp> future<_Rp>
64  get_future();
65  template <class _Rp>
66  struct shared_future<_Rp&> {
67    shared_future(future<_Rp&>&& __f); // expected-warning {{rvalue references are a C++11 extension}}
68  };
69  void f() {
70    typedef int T;
71    get_future<int>();
72    typedef int& U;
73    shared_future<int&> f1 = get_future<int&>();
74  }
75}
76
77// This is OK. The variables have internal linkage and therefore no language
78// linkage.
79extern "C" {
80  static int test7_x;
81}
82extern "C++" {
83  extern int test7_x;
84}
85extern "C++" {
86  static int test7_y;
87}
88extern "C" {
89  extern int test7_y;
90}
91extern "C" { typedef int test7_F(); static test7_F test7_f; }
92extern "C++" { extern test7_F test7_f; }
93
94// FIXME: This should be invalid. The function has no language linkage, but
95// the function type has, so this is redeclaring the function with a different
96// type.
97extern "C++" {
98  static void test8_f();
99}
100extern "C" {
101  extern void test8_f();
102}
103extern "C" {
104  static void test8_g();
105}
106extern "C++" {
107  extern void test8_g();
108}
109
110extern "C" {
111  void __attribute__((overloadable)) test9_f(int c); // expected-note {{previous declaration is here}}
112}
113extern "C++" {
114  void __attribute__((overloadable)) test9_f(int c); // expected-error {{declaration of 'test9_f' has a different language linkage}}
115}
116
117extern "C" {
118  void __attribute__((overloadable)) test10_f(int);
119  void __attribute__((overloadable)) test10_f(double);
120}
121
122extern "C" {
123  void test11_f() {
124    void  __attribute__((overloadable)) test11_g(int);
125    void  __attribute__((overloadable)) test11_g(double);
126  }
127}
128