hanchenye-llvm-project/clang/test/Sema/function.c

90 lines
2.7 KiB
C
Raw Normal View History

// RUN: clang-cc %s -fsyntax-only -verify -pedantic
// PR1892
void f(double a[restrict][5]); // should promote to restrict ptr.
void f(double (* restrict a)[5]);
int foo (__const char *__path);
int foo(__const char *__restrict __file);
void func(const char*); // expected-note {{previous declaration is here}}
void func(char*); // expected-error{{conflicting types for 'func'}}
void g(int (*)(const void **, const void **));
void g(int (*compar)()) {
}
void h(); // expected-note {{previous declaration is here}}
void h (const char *fmt, ...) {} // expected-error{{conflicting types for 'h'}}
2008-01-31 14:06:29 +08:00
// PR1965
int t5(b); // expected-error {{parameter list without types}}
int t6(int x, g); // expected-warning {{type specifier missing, defaults to 'int'}}
2008-01-31 14:06:29 +08:00
int t7(, ); // expected-error {{expected parameter declarator}} expected-error {{expected parameter declarator}}
int t8(, int a); // expected-error {{expected parameter declarator}}
int t9(int a, ); // expected-error {{expected parameter declarator}}
2008-01-31 14:06:29 +08:00
// PR2042
void t10(){}
void t11(){t10(1);} // expected-warning{{too many arguments}}
// PR3208
void t12(int) {} // expected-error{{parameter name omitted}}
// PR2790
void t13() {
return 0; // expected-warning {{void function 't13' should not return a value}}
}
int t14() {
return; // expected-warning {{non-void function 't14' should return a value}}
}
// <rdar://problem/6097326>
y(y) { return y; } // expected-warning{{parameter 'y' was not declared, defaulting to type 'int'}} \
// expected-warning{{type specifier missing, defaults to 'int'}}
2009-02-05 02:50:00 +08:00
// PR3137, <rdar://problem/6127293>
2009-02-05 02:50:00 +08:00
extern int g0_3137(void);
void f0_3137() {
int g0_3137(void);
}
void f1_3137() {
int (*fp)(void) = g0_3137;
}
void f1static() {
static void f2static(int); // expected-error{{function declared in block scope cannot have 'static' storage class}}
register void f2register(int); // expected-error{{illegal storage class on function}}
}
struct incomplete_test a(void) {} // expected-error{{incomplete result type 'struct incomplete_test' in function definition}} \
// expected-note{{forward declaration of 'struct incomplete_test'}}
extern __inline
Simplify the scheme used for keywords, and change the classification scheme to be more useful. The new scheme introduces a set of categories that should be more readable, and also reflects what we want to consider as an extension more accurately. Specifically, it makes the "what is a keyword" determination accurately reflect whether the keyword is a GNU or Microsoft extension. I also introduced separate flags for keyword aliases; this is useful because the classification of the aliases is mostly unrelated to the classification of the original keyword. This patch treats anything that's in the implementation namespace (prefixed with "__", or "_X" where "X" is any upper-case letter) as a keyword without marking it as an extension. This is consistent with the standards in that an implementation is allowed to define arbitrary extensions in the implementation namespace without violating the standard. This gets rid of all the nasty "extension used" warnings for stuff like __attribute__ in -pedantic mode. We still warn for extensions outside of the the implementation namespace, like typeof. If someone wants to implement -Wextensions or something like that, we could add additional information to the keyword table. This also removes processing for the unused "Boolean" language option; such an extension isn't supported on any other C implementation, so I don't see any point to adding it. The changes to test/CodeGen/inline.c are required because previously, we weren't actually disabling the "inline" keyword in -std=c89 mode. I'll remove Boolean and NoExtensions from LangOptions in a follow-up commit. llvm-svn: 70281
2009-04-28 11:13:54 +08:00
__attribute__((__gnu_inline__))
void gnu_inline1() {}
void
Simplify the scheme used for keywords, and change the classification scheme to be more useful. The new scheme introduces a set of categories that should be more readable, and also reflects what we want to consider as an extension more accurately. Specifically, it makes the "what is a keyword" determination accurately reflect whether the keyword is a GNU or Microsoft extension. I also introduced separate flags for keyword aliases; this is useful because the classification of the aliases is mostly unrelated to the classification of the original keyword. This patch treats anything that's in the implementation namespace (prefixed with "__", or "_X" where "X" is any upper-case letter) as a keyword without marking it as an extension. This is consistent with the standards in that an implementation is allowed to define arbitrary extensions in the implementation namespace without violating the standard. This gets rid of all the nasty "extension used" warnings for stuff like __attribute__ in -pedantic mode. We still warn for extensions outside of the the implementation namespace, like typeof. If someone wants to implement -Wextensions or something like that, we could add additional information to the keyword table. This also removes processing for the unused "Boolean" language option; such an extension isn't supported on any other C implementation, so I don't see any point to adding it. The changes to test/CodeGen/inline.c are required because previously, we weren't actually disabling the "inline" keyword in -std=c89 mode. I'll remove Boolean and NoExtensions from LangOptions in a follow-up commit. llvm-svn: 70281
2009-04-28 11:13:54 +08:00
__attribute__((__gnu_inline__)) // expected-warning {{'gnu_inline' attribute requires function to be marked 'inline', attribute ignored}}
gnu_inline2() {}
// rdar://6802350
inline foo_t invalid_type() { // expected-error {{unknown type name 'foo_t'}}
}
typedef void fn_t(void);
fn_t t17;
// PR4049
unknown_type t18(void*) { // expected-error {{unknown type name 'unknown_type'}} expected-error{{parameter name omitted}}
}
unknown_type t19(int* P) { // expected-error {{unknown type name 'unknown_type'}}
P = P+1; // no warning.
}