summaryrefslogtreecommitdiff
path: root/test/Sema/function-redecl.c
blob: 9544dc9baef698569ff42b30ffb7cef340381a46 (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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// RUN: %clang_cc1 -fsyntax-only -verify %s

// PR3588
void g0(int, int);
void g0(); // expected-note{{previous declaration is here}}

void f0() {
  g0(1, 2, 3); // expected-error{{too many arguments to function call}}
}

void g0(int); // expected-error{{conflicting types for 'g0'}}

int g1(int, int);

typedef int INT;

INT g1(x, y)
     int x;
     int y;
{
  return x + y;
}

int g2(int, int); // expected-note{{previous declaration is here}}

INT g2(x) // expected-error{{conflicting types for 'g2'}}
     int x;
{
  return x;
}

void test() {
  int f1;
  {
    void f1(double);
    {
      void f1(double); // expected-note{{previous declaration is here}}
      {
        int f1(int); // expected-error{{conflicting types for 'f1'}}
      }
    }
  }
}

extern void g3(int); // expected-note{{previous declaration is here}}
static void g3(int x) { } // expected-error{{static declaration of 'g3' follows non-static declaration}}

void test2() {
  extern int f2; // expected-note 2 {{previous definition is here}}
  {
    void f2(int); // expected-error{{redefinition of 'f2' as different kind of symbol}}
  }

  {
    int f2;
    {
      void f2(int); // expected-error{{redefinition of 'f2' as different kind of symbol}}
    }
  }
}

// <rdar://problem/6127293>
int outer1(int); // expected-note{{previous declaration is here}}
struct outer3 { };
int outer4(int);
int outer5; // expected-note{{previous definition is here}}
int *outer7(int);

void outer_test() {
  int outer1(float); // expected-error{{conflicting types for 'outer1'}}
  int outer2(int); // expected-note{{previous declaration is here}}
  int outer3(int); // expected-note{{previous declaration is here}}
  int outer4(int); // expected-note{{previous declaration is here}}
  int outer5(int); // expected-error{{redefinition of 'outer5' as different kind of symbol}}
  int* outer6(int); // expected-note{{previous declaration is here}}
  int *outer7(int);
  int outer8(int);

  int *ip7 = outer7(6);
}

int outer2(float); // expected-error{{conflicting types for 'outer2'}}
int outer3(float); // expected-error{{conflicting types for 'outer3'}}
int outer4(float); // expected-error{{conflicting types for 'outer4'}}

void outer_test2(int x) {
  int* ip = outer6(x); // expected-warning{{use of out-of-scope declaration of 'outer6'}}
  int *ip2 = outer7(x);
}

void outer_test3() {
  int *(*fp)(int) = outer8; // expected-error{{use of undeclared identifier 'outer8'}}
}

static float outer8(float); // okay

enum e { e1, e2 };

// GNU extension: prototypes and K&R function definitions
int isroot(short x, // expected-note{{previous declaration is here}}
           enum e); 

int isroot(x, y)
     short x; // expected-warning{{promoted type 'int' of K&R function parameter is not compatible with the parameter type 'short' declared in a previous prototype}}
     unsigned int y;
{
  return x == 1;
}

// PR3817
void *h0(unsigned a0,     ...);
extern __typeof (h0) h1 __attribute__((__sentinel__));
extern __typeof (h1) h1 __attribute__((__sentinel__));

// PR3840
void i0 (unsigned short a0);
extern __typeof (i0) i1;
extern __typeof (i1) i1;

typedef int a();
typedef int a2(int*);
a x;
a2 x2;
void test_x() {
  x(5);
  x2(5); // expected-warning{{incompatible integer to pointer conversion passing 'int', expected 'int *'}}
}