[cfe-dev] Unneeded declarations invalidation
Enea Zaffanella
zaffanella at cs.unipr.it
Tue Jul 7 03:46:18 PDT 2009
The following (non-standard compliant) code is rejected by clang
but accepted by gcc.
==================
static struct q b;
struct q {
int i;
};
void foo(void) {
b.i = 1;
}
==================
Up to my understanding, the code above is harmless and can be compiled
into well defined low-level code.
The attached patch introduces a new warning
warn_typecheck_decl_incomplete_type
and downgrades the diagnostic generated for cases such as the one above,
which are currently reporting an
err_typecheck_decl_incomplete_type
so as to report the new warning and do not invalidate the static
tentative definition.
It passes all of the tests, modulo the obvious adaptation of the
expected outputs (which is included in the patch).
As a result, the patched clang produces the following:
==================
Debug/bin/clang-cc -ast-print bug2.c
bug2.c:1:17: warning: variable has incomplete
type 'struct q'
static struct q b;
^
bug2.c:1:15: note: forward declaration of
'struct q'
static struct q b;
^
[...SNIP..]
struct q;
static struct q b;
struct q {
int i;
};
int foo() {
b.i = 1;
}
2 diagnostics generated.
========================
Is that ok?
Cheers,
Enea Zaffanella.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: StaticForwardDeclStruct.patch
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20090707/ac56692b/attachment.ksh>
More information about the cfe-dev
mailing list