[cfe-dev] Implicit function declaration warnings
matthijs at stdin.nl
Tue Aug 19 07:15:29 PDT 2008
I was wondering why my frontend wasn't generating any warnings where I
expected them and had a look at the source. I found something typical where
implicit function declarations are concerned.
In Sema/SemaDecl.cpp, in Sema::ImplicitlyDefineFunction, a diagnostic is
generated for implicit declarations. When not in C99 mode, this works as
expected, a diagnostic of type diag::warn_implicit_function_decl is generated
which is enabled through -Wimplicit-function-declaration.
However, when in C99 mode implicit declarations no longer generate a normal
warning, but an extension warning of type diag::ext_implicit_function_decl.
This is a bit weird (since, if I read the warning correctly, an implicit
function declaration should be an error in C99 mode), but I that ignoring this
new constraint in C99 is a gcc "feature".
Anyway, this means that when I compile in C99 mode, I won't get implicit
function declaration warnings, even when I explicitely specify
-Wimplicit-function-declaration. This is of course unexpected and, IMHO
I've attached a patch which makes clang explicitly map the
diag::ext_implicit_function_decl diagnostic type as a WARNING, when
-Wimplicit-function-declaraton is given. This has the desired effect, though
I'm not completely sure that this is the right approach. In particular, the
error messages is now slightly confusing, it says:
foo.c:21:3: warning: implicit declaration of function 'printf' is invalid in C99
Thinking a bit more on this, it seems this stuff is mainly caused by clang
supporting gcc's extensions out of the box. IMHO it would be better to be able
to toggle these extensions seperately, and giving errors for extensions not
enabled, or giving warnings for extensions that are enabled only when
-pedantic is given.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 189 bytes
Desc: Digital signature
More information about the cfe-dev