summaryrefslogtreecommitdiff
path: root/test/Sema/extern-redecl.c
blob: 6bdb66e07f5538a6d12222d23fdaedd6961da20d (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
// RUN: %clang_cc1 -fsyntax-only -verify %s

// rdar: // 8125274
static int a16[];  // expected-warning {{tentative array definition assumed to have one element}}

void f16(void) {
    extern int a16[];
}


// PR10013: Scope of extern declarations extend past enclosing block
extern int PR10013_x;
int PR10013(void) {
  int *PR10013_x = 0;
  {
    extern int PR10013_x;
    extern int PR10013_x; 
  }
  
  return PR10013_x; // expected-warning{{incompatible pointer to integer conversion}}
}

static int test1_a[]; // expected-warning {{tentative array definition assumed to have one element}}
extern int test1_a[];

// rdar://13535367
void test2declarer() { extern int test2_array[100]; }
extern int test2_array[];
int test2v = sizeof(test2_array); // expected-error {{invalid application of 'sizeof' to an incomplete type 'int []'}}

void test3declarer() {
  { extern int test3_array[100]; }
  extern int test3_array[];
  int x = sizeof(test3_array); // expected-error {{invalid application of 'sizeof' to an incomplete type 'int []'}}
}

void test4() {
  extern int test4_array[];
  {
    extern int test4_array[100];
    int x = sizeof(test4_array); // fine
  }
  int x = sizeof(test4_array); // expected-error {{invalid application of 'sizeof' to an incomplete type 'int []'}}
}

// Test that invalid local extern declarations of library
// builtins behave reasonably.
extern void abort(void); // expected-note 2 {{previous declaration is here}}
extern float *calloc(); // expected-warning {{incompatible redeclaration of library function}} expected-note {{is a builtin}} expected-note 2 {{previous declaration is here}}
void test5a() {
  int abort(); // expected-error {{conflicting types}}
  float *malloc(); // expected-warning {{incompatible redeclaration of library function}} expected-note 2 {{is a builtin}}
  int *calloc(); // expected-error {{conflicting types}}
}
void test5b() {
  int abort(); // expected-error {{conflicting types}}
  float *malloc(); // expected-warning {{incompatible redeclaration of library function}}
  int *calloc(); // expected-error {{conflicting types}}
}
void test5c() {
  void (*_abort)(void) = &abort;
  void *(*_malloc)() = &malloc;
  float *(*_calloc)() = &calloc;
}

void test6() {
  extern int test6_array1[100];
  extern int test6_array2[100];
  void test6_fn1(int*);
  void test6_fn2(int*);
  {
    // Types are only merged from visible declarations.
    char test6_array2;
    char test6_fn2;
    {
      extern int test6_array1[];
      extern int test6_array2[];
      (void)sizeof(test6_array1); // ok
      (void)sizeof(test6_array2); // expected-error {{incomplete type}}

      void test6_fn1();
      void test6_fn2();
      test6_fn1(1.2); // expected-error {{passing 'double' to parameter of incompatible type 'int *'}}
      // FIXME: This is valid, but we should warn on it.
      test6_fn2(1.2);
    }
  }
}