1 // RUN: %clang_cc1 %s -verify=expected,both -fsyntax-only -Werror=implicit-function-declaration -std=c99
2 // RUN: %clang_cc1 %s -verify=expected,both -fsyntax-only -std=c11
3 // RUN: %clang_cc1 %s -verify=c2x,both -fsyntax-only -std=c2x
5 /// -Werror-implicit-function-declaration is a deprecated alias used by many projects.
6 // RUN: %clang_cc1 %s -verify=expected,both -fsyntax-only -Werror-implicit-function-declaration
8 // c2x-note@*:* {{'__builtin_va_list' declared here}}
11 typedef unsigned char Boolean
;
13 extern int printf(__const
char *__restrict __format
, ...); // both-note{{'printf' declared here}}
16 const char compDesc
[16 + 1];
17 int32_t compCount
= 0;
18 if (_CFCalendarDecomposeAbsoluteTimeV(compDesc
, vector
, compCount
)) { // expected-error {{call to undeclared function '_CFCalendarDecomposeAbsoluteTimeV'; ISO C99 and later do not support implicit function declarations}} \
19 expected
-note
{{previous implicit declaration
}} \
20 c2x
-error
{{use of undeclared identifier
'_CFCalendarDecomposeAbsoluteTimeV'}}
23 printg("Hello, World!\n"); // expected-error{{call to undeclared function 'printg'; ISO C99 and later do not support implicit function declarations}} \
24 expected
-note
{{did you mean
'printf'?}} \
25 c2x
-error
{{use of undeclared identifier
'printg'; did you mean
'printf'?}}
27 __builtin_is_les(1, 3); // expected-error{{use of unknown builtin '__builtin_is_les'}} \
28 c2x
-error
{{unknown type name
'__builtin_is_les'; did you mean
'__builtin_va_list'?}} \
29 c2x
-error
{{expected identifier
or '('}} \
30 c2x
-error
{{expected
')'}} \
31 c2x
-note
{{to match
this '('}}
33 Boolean
_CFCalendarDecomposeAbsoluteTimeV(const char *componentDesc
, int32_t **vector
, int32_t count
) { // expected-error {{conflicting types}}
38 // Test the typo-correction callback in Sema::ImplicitlyDefineFunction
39 extern int sformatf(char *str
, __const
char *__restrict __format
, ...); // expected-note{{'sformatf' declared here}}
40 void test_implicit(void) {
41 int formats
= 0; // c2x-note {{'formats' declared here}}
42 formatd("Hello, World!\n"); // expected-error{{call to undeclared function 'formatd'; ISO C99 and later do not support implicit function declarations}} \
43 expected
-note
{{did you mean
'sformatf'?}} \
44 c2x
-error
{{use of undeclared identifier
'formatd'; did you mean
'formats'?}} \
45 c2x
-error
{{called object type
'int' is
not a function
or function pointer
}}
48 void test_suggestion(void) {
49 bark(); // expected-error {{call to undeclared function 'bark'; ISO C99 and later do not support implicit function declarations}} \
50 c2x
-error
{{use of undeclared identifier
'bark'}}
51 bork(); // expected-error {{call to undeclared function 'bork'; ISO C99 and later do not support implicit function declarations}} \
52 c2x
-error
{{use of undeclared identifier
'bork'}}
55 // The following used to cause an assertion from trying to define the implicit
56 // function within a structure scope as opposed to within function or global
60 int x
__attribute__((aligned(({ a(); })))); // expected-error {{call to undeclared function 'a'; ISO C99 and later do not support implicit function declarations}} \
61 c2x
-error
{{use of undeclared identifier
'a'}} \
62 both
-error
{{'aligned' attribute requires integer constant
}}
66 void GH48579_2(void) {
68 int array
[({ a(); })]; // expected-error {{call to undeclared function 'a'; ISO C99 and later do not support implicit function declarations}} \
69 c2x
-error
{{use of undeclared identifier
'a'}} \
70 expected
-error
{{fields must have a constant size
: 'variable length array in structure' extension will never be supported
}} \
71 c2x
-error
{{size of array has non
-integer type
'void'}}
75 int GH48579_3
= ({a();}); // both-error {{statement expression not allowed at file scope}}
76 void GH48579_4(int array
[({ a(); })]); // both-error {{statement expression not allowed at file scope}}
78 void pragma_warning(void) {
79 #pragma clang diagnostic warning "-Wimplicit-function-declaration"
80 bark(); // expected-warning {{call to undeclared function 'bark'; ISO C99 and later do not support implicit function declarations}} \
81 c2x
-error
{{use of undeclared identifier
'bark'}}
84 void pragma_error(void) {
85 #pragma clang diagnostic error "-Wimplicit-function-declaration"
86 bark(); // expected-error {{call to undeclared function 'bark'; ISO C99 and later do not support implicit function declarations}} \
87 c2x
-error
{{use of undeclared identifier
'bark'}}
90 void pragma_ignored(void) {
91 #pragma clang diagnostic ignored "-Wimplicit-function-declaration"
92 bark(); // c2x-error {{use of undeclared identifier 'bark'}}