2011-12-06 17:46:12 +08:00
|
|
|
/* RUN: %clang_cc1 %s -std=c89 -pedantic -fsyntax-only -verify -Wimplicit-function-declaration
|
2007-08-27 12:29:41 +08:00
|
|
|
*/
|
2007-08-29 00:54:00 +08:00
|
|
|
void test1() {
|
2007-08-27 12:29:41 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
i = i + 1;
|
|
|
|
int j; /* expected-warning {{mixing declarations and code}} */
|
|
|
|
}
|
|
|
|
{
|
|
|
|
__extension__ int i;
|
|
|
|
i = i + 1;
|
|
|
|
int j; /* expected-warning {{mixing declarations and code}} */
|
|
|
|
}
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
i = i + 1;
|
|
|
|
__extension__ int j; /* expected-warning {{mixing declarations and code}} */
|
|
|
|
}
|
|
|
|
}
|
2007-08-29 00:40:32 +08:00
|
|
|
|
2007-08-29 00:54:00 +08:00
|
|
|
long long test2; /* expected-warning {{extension}} */
|
2007-08-29 00:40:32 +08:00
|
|
|
|
2007-08-29 00:54:00 +08:00
|
|
|
|
|
|
|
void test3(int i) {
|
|
|
|
int A[i]; /* expected-warning {{variable length array}} */
|
|
|
|
}
|
2007-08-30 06:00:19 +08:00
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
int test4 = 0LL; /* expected-warning {{long long}} */
|
2007-08-30 06:00:19 +08:00
|
|
|
|
2008-02-11 07:08:00 +08:00
|
|
|
/* PR1999 */
|
|
|
|
void test5(register);
|
|
|
|
|
2008-02-16 02:02:59 +08:00
|
|
|
/* PR2041 */
|
|
|
|
int *restrict;
|
2008-02-19 14:46:10 +08:00
|
|
|
int *__restrict; /* expected-error {{expected identifier}} */
|
2008-04-05 13:52:15 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* Implicit int, always ok */
|
2009-07-22 08:43:08 +08:00
|
|
|
test6() { return 0; }
|
2008-04-05 14:32:51 +08:00
|
|
|
|
|
|
|
/* PR2012 */
|
|
|
|
test7; /* expected-warning {{declaration specifier missing, defaulting to 'int'}} */
|
|
|
|
|
|
|
|
void test8(int, x); /* expected-warning {{declaration specifier missing, defaulting to 'int'}} */
|
|
|
|
|
|
|
|
typedef int sometype;
|
2008-12-17 15:32:46 +08:00
|
|
|
int a(sometype, y) {return 0;} /* expected-warning {{declaration specifier missing, defaulting to 'int'}} \
|
|
|
|
expected-error {{parameter name omitted}}*/
|
2008-04-05 13:52:15 +08:00
|
|
|
|
|
|
|
|
2008-04-10 10:22:51 +08:00
|
|
|
|
|
|
|
|
|
|
|
void bar (void *);
|
|
|
|
void f11 (z) /* expected-error {{may not have 'void' type}} */
|
|
|
|
void z;
|
|
|
|
{ bar (&z); }
|
|
|
|
|
|
|
|
typedef void T;
|
2008-04-10 10:26:16 +08:00
|
|
|
void foo(T); /* typedef for void is allowed */
|
|
|
|
|
|
|
|
void foo(void) {}
|
2008-04-10 10:22:51 +08:00
|
|
|
|
2008-12-18 14:50:14 +08:00
|
|
|
/* PR2759 */
|
2011-12-30 05:57:33 +08:00
|
|
|
void test10 (int x[*]); /* expected-warning {{variable length arrays are a C99 feature}} */
|
|
|
|
void test11 (int x[static 4]); /* expected-warning {{static array size is a C99 feature}} */
|
2008-12-18 14:50:14 +08:00
|
|
|
|
2011-12-30 05:57:33 +08:00
|
|
|
void test12 (int x[const 4]) { /* expected-warning {{qualifier in array size is a C99 feature}} */
|
|
|
|
int Y[x[1]]; /* expected-warning {{variable length arrays are a C99 feature}} */
|
2008-12-18 14:50:14 +08:00
|
|
|
}
|
2009-04-26 07:46:54 +08:00
|
|
|
|
|
|
|
/* PR4074 */
|
|
|
|
struct test13 {
|
|
|
|
int X[23];
|
|
|
|
} test13a();
|
|
|
|
|
|
|
|
void test13b() {
|
|
|
|
int a = test13a().X[1]; /* expected-warning {{ISO C90 does not allow subscripting non-lvalue array}} */
|
|
|
|
int b = 1[test13a().X]; /* expected-warning {{ISO C90 does not allow subscripting non-lvalue array}} */
|
|
|
|
}
|
|
|
|
|
2009-04-29 01:59:09 +08:00
|
|
|
/* Make sure we allow *test14 as a "function designator" */
|
|
|
|
int test14() { return (&*test14)(); }
|
2011-04-25 06:14:22 +08:00
|
|
|
|
|
|
|
int test15[5] = { [2] = 1 }; /* expected-warning {{designated initializers are a C99 feature}} */
|
2011-12-06 17:46:12 +08:00
|
|
|
|
2011-12-08 23:56:07 +08:00
|
|
|
extern int printf(__const char *__restrict __format, ...);
|
2011-12-06 17:46:12 +08:00
|
|
|
|
2011-12-08 23:56:07 +08:00
|
|
|
/* Warn, but don't suggest typo correction. */
|
2011-12-06 17:46:12 +08:00
|
|
|
void test16() {
|
2011-12-08 23:56:07 +08:00
|
|
|
printg("Hello, world!\n"); /* expected-warning {{implicit declaration of function 'printg'}} */
|
2011-12-06 17:46:12 +08:00
|
|
|
}
|
2012-02-15 03:50:52 +08:00
|
|
|
|
2013-11-02 18:38:05 +08:00
|
|
|
struct x { int x,y[]; }; /* expected-warning {{flexible array members are a C99 feature}} */
|
2012-03-16 20:15:37 +08:00
|
|
|
|
2012-04-06 06:47:34 +08:00
|
|
|
/* Duplicated type-qualifiers aren't allowed by C90 */
|
|
|
|
const const int c_i; /* expected-warning {{duplicate 'const' declaration specifier}} */
|
|
|
|
typedef volatile int vol_int;
|
|
|
|
volatile vol_int volvol_i; /* expected-warning {{duplicate 'volatile' declaration specifier}} */
|
|
|
|
typedef volatile vol_int volvol_int; /* expected-warning {{duplicate 'volatile' declaration specifier}} */
|
|
|
|
const int * const c;
|
|
|
|
|
|
|
|
typedef const int CI;
|
|
|
|
|
|
|
|
const CI mine1[5][5]; /* expected-warning {{duplicate 'const' declaration specifier}} */
|
|
|
|
|
|
|
|
typedef CI array_of_CI[5];
|
|
|
|
const array_of_CI mine2; /* expected-warning {{duplicate 'const' declaration specifier}} */
|
|
|
|
|
|
|
|
typedef CI *array_of_pointer_to_CI[5];
|
|
|
|
const array_of_pointer_to_CI mine3;
|
|
|
|
|
2012-02-15 03:50:52 +08:00
|
|
|
void main() {} /* expected-error {{'main' must return 'int'}} */
|
2012-09-25 02:19:21 +08:00
|
|
|
|
2014-07-02 15:07:20 +08:00
|
|
|
const int main() {} /* expected-error {{'main' must return 'int'}} */
|
|
|
|
|
2012-09-25 02:19:21 +08:00
|
|
|
long long ll1 = /* expected-warning {{'long long' is an extension when C99 mode is not enabled}} */
|
|
|
|
-42LL; /* expected-warning {{'long long' is an extension when C99 mode is not enabled}} */
|
|
|
|
unsigned long long ull1 = /* expected-warning {{'long long' is an extension when C99 mode is not enabled}} */
|
|
|
|
42ULL; /* expected-warning {{'long long' is an extension when C99 mode is not enabled}} */
|
|
|
|
|
2013-07-23 03:10:20 +08:00
|
|
|
struct Test17 { int a; };
|
|
|
|
struct Test17 test17_aux(void);
|
|
|
|
|
2013-07-22 18:58:26 +08:00
|
|
|
void test17(int v, int w) {
|
|
|
|
int a[2] = { v, w }; /* expected-warning {{initializer for aggregate is not a compile-time constant}} */
|
2013-07-23 03:10:20 +08:00
|
|
|
struct Test17 t0 = { v }; /* expected-warning {{initializer for aggregate is not a compile-time constant}} */
|
|
|
|
struct Test17 t1 = test17_aux(); /* this is allowed */
|
2013-07-22 18:58:26 +08:00
|
|
|
}
|
|
|
|
|