def ext_implicit_function_decl : ExtWarn<
"implicit declaration of function %0 is invalid in C99">,
InGroup<ImplicitFunctionDeclare>;
+def note_function_suggestion : Note<"did you mean %0?">;
def err_ellipsis_first_arg : Error<
"ISO C requires a named argument before '...'">;
def err_builtin_definition : Error<"definition of builtin function %0">;
def err_types_compatible_p_in_cplusplus : Error<
"__builtin_types_compatible_p is not valid in C++">;
-def warn_builtin_unknown : Warning<"use of unknown builtin %0">, DefaultError;
+def err_builtin_unknown : Error<"use of unknown builtin %0">;
def warn_dyn_class_memaccess : Warning<
"%select{destination for|source of|first operand of|second operand of}0 this "
"%1 call is a pointer to dynamic class %2; vtable pointer will be "
return Pos->second;
}
+ // See if we can find a typo correction.
+ TypoCorrection Corrected;
+ FunctionDecl *Func = 0;
+ std::string CorrectedStr;
+ std::string CorrectedQuotedStr;
+ if (S && (Corrected = CorrectTypo(DeclarationNameInfo(&II, Loc),
+ LookupOrdinaryName, S, 0))) {
+ // Since this is an implicit function declaration, we are only
+ // interested in a potential typo for a function name.
+ if ((Func = dyn_cast_or_null<FunctionDecl>(
+ Corrected.getCorrectionDecl()))) {
+ CorrectedStr = Corrected.getAsString(getLangOptions());
+ CorrectedQuotedStr = Corrected.getQuoted(getLangOptions());
+ }
+ }
+
// Extension in C99. Legal in C90, but warn about it.
if (II.getName().startswith("__builtin_"))
- Diag(Loc, diag::warn_builtin_unknown) << &II;
+ Diag(Loc, diag::err_builtin_unknown) << &II;
else if (getLangOptions().C99)
Diag(Loc, diag::ext_implicit_function_decl) << &II;
else
Diag(Loc, diag::warn_implicit_function_decl) << &II;
+ if (Func) {
+ // If we found a typo correction, then suggest that.
+ Diag(Loc, diag::note_function_suggestion) << CorrectedQuotedStr
+ << FixItHint::CreateReplacement(Loc, CorrectedStr);
+ if (Func->getLocation().isValid() && !II.getName().startswith("__builtin_"))
+ Diag(Func->getLocation(), diag::note_previous_decl) << CorrectedQuotedStr;
+ }
+
// Set a Declarator for the implicit definition: int foo();
const char *Dummy;
AttributeFactory attrFactory;
The list of warnings below should NEVER grow. It should gradually shrink to 0.
-CHECK: Warnings without flags (272):
+CHECK: Warnings without flags (271):
CHECK-NEXT: ext_anon_param_requires_type_specifier
CHECK-NEXT: ext_anonymous_struct_union_qualified
CHECK-NEXT: ext_array_init_copy
CHECK-NEXT: warn_bitfield_width_exceeds_type_size
CHECK-NEXT: warn_bool_switch_condition
CHECK-NEXT: warn_braces_around_scalar_init
-CHECK-NEXT: warn_builtin_unknown
CHECK-NEXT: warn_c_kext
CHECK-NEXT: warn_call_to_pure_virtual_member_function_from_ctor_dtor
CHECK-NEXT: warn_call_wrong_number_of_arguments
}
void test_unknown_builtin(int a, int b) {
- __builtin_foo(a, b); // expected-error{{use of unknown builtin}}
+ __builtin_isles(a, b); // expected-error{{use of unknown builtin}} \
+ // expected-note{{did you mean '__builtin_isless'?}}
}
int test13() {
return __builtin_constant_p() + // expected-error{{too few arguments}}
__builtin_constant_p(1, 2); // expected-error {{too many arguments}}
}
-
-/* RUN: %clang_cc1 %s -std=c89 -pedantic -fsyntax-only -verify
+/* RUN: %clang_cc1 %s -std=c89 -pedantic -fsyntax-only -verify -Wimplicit-function-declaration
*/
void test1() {
{
int test14() { return (&*test14)(); }
int test15[5] = { [2] = 1 }; /* expected-warning {{designated initializers are a C99 feature}} */
+
+extern int printf(__const char *__restrict __format, ...); /* expected-note{{'printf' declared here}} */
+
+void test16() {
+ printg("Hello, world!\n"); /* expected-warning {{implicit declaration of function 'printg'}}
+ expected-note {{did you mean 'printf'?}} */
+}
typedef int int32_t;
typedef unsigned char Boolean;
+extern int printf(__const char *__restrict __format, ...); // expected-note{{'printf' declared here}}
+
void func() {
int32_t *vector[16];
const char compDesc[16 + 1];
if (_CFCalendarDecomposeAbsoluteTimeV(compDesc, vector, compCount)) { // expected-note {{previous implicit declaration is here}} \
expected-warning {{implicit declaration of function '_CFCalendarDecomposeAbsoluteTimeV' is invalid in C99}}
}
+
+ printg("Hello, World!\n"); // expected-warning{{implicit declaration of function 'printg' is invalid in C99}} \
+ // expected-note{{did you mean 'printf'?}}
+
+ __builtin_is_les(1, 3); // expected-error{{use of unknown builtin '__builtin_is_les'}} \
+ // expected-note{did you mean '__builtin_is_less'?}}
}
Boolean _CFCalendarDecomposeAbsoluteTimeV(const char *componentDesc, int32_t **vector, int32_t count) { // expected-error{{conflicting types for '_CFCalendarDecomposeAbsoluteTimeV'}}
return 0;
}
-