[cfe-dev] Implicit function declaration warnings

Matthijs Kooijman matthijs at stdin.nl
Tue Aug 19 07:15:29 PDT 2008


Hi all,

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
unwanted.

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.

Any thoughts?

Gr.

Matthijs
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20080819/ee013480/attachment.sig>


More information about the cfe-dev mailing list