summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaCXX/extern-c.cpp
blob: 220b2a8dc1e5cbae077e6dadb89670d37d7c90f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// RUN: %clang_cc1 -fsyntax-only -verify %s

namespace test1 {
  extern "C" {
    void test1_f() {
      void test1_g(int); // expected-note {{previous declaration is here}}
    }
  }
}
int test1_g(int); // expected-error {{functions that differ only in their return type cannot be overloaded}}

namespace test2 {
  extern "C" {
    void test2_f() {
      extern int test2_x; // expected-note {{previous definition is here}}
    }
  }
}
float test2_x; // expected-error {{redefinition of 'test2_x' with a different type: 'float' vs 'int'}}

namespace test3 {
  extern "C" {
    void test3_f() {
      extern int test3_b; // expected-note {{previous definition is here}}
    }
  }
  extern "C" {
    float test3_b; // expected-error {{redefinition of 'test3_b' with a different type: 'float' vs 'int'}}
  }
}

extern "C" {
  void test4_f() {
    extern int test4_b; // expected-note {{previous definition is here}}
  }
}
static float test4_b; // expected-error {{redefinition of 'test4_b' with a different type: 'float' vs 'int'}}

extern "C" {
  void test5_f() {
    extern int test5_b; // expected-note {{previous definition is here}}
  }
}
extern "C" {
  static float test5_b; // expected-error {{redefinition of 'test5_b' with a different type: 'float' vs 'int'}}
}

extern "C" {
  void f() {
    extern int test6_b;
  }
}
namespace foo {
  extern "C" {
    static float test6_b;
    extern float test6_b;
  }
}

namespace linkage {
  namespace redecl {
    extern "C" {
      static void linkage_redecl();
      static void linkage_redecl(int);
      void linkage_redecl(); // ok, still not extern "C"
      void linkage_redecl(int); // ok, still not extern "C"
      void linkage_redecl(float); // expected-note {{previous}}
      void linkage_redecl(double); // expected-error {{conflicting types}}
    }
  }
  namespace from_outer {
    void linkage_from_outer_1();
    void linkage_from_outer_2(); // expected-note {{previous}}
    extern "C" {
      void linkage_from_outer_1(int); // expected-note {{previous}}
      void linkage_from_outer_1(); // expected-error {{conflicting types}}
      void linkage_from_outer_2(); // expected-error {{different language linkage}}
    }
  }
  namespace mixed {
    extern "C" {
      void linkage_mixed_1();
      static void linkage_mixed_1(int);

      static void linkage_mixed_2(int);
      void linkage_mixed_2();
    }
  }
  namespace across_scopes {
    namespace X {
      extern "C" void linkage_across_scopes_f() {
        void linkage_across_scopes_g(); // expected-note {{previous}}
      }
    }
    namespace Y {
      extern "C" void linkage_across_scopes_g(int); // expected-error {{conflicting}}
    }
  }
}

void lookup_in_global_f();
namespace lookup_in_global {
  void lookup_in_global_f();
  extern "C" {
    // FIXME: We should reject this.
    void lookup_in_global_f(int);
  }
}
OpenPOWER on IntegriCloud