On Fri, 15 Jan 2016, Prathamesh Kulkarni wrote: > On 15 January 2016 at 03:27, Joseph Myers <jos...@codesourcery.com> wrote: > > On Thu, 14 Jan 2016, Prathamesh Kulkarni wrote: > > > >> Hi, > >> For test-case containing only the following declaration: > >> static struct undefined_struct object; > >> gcc rejects it at -O0 in assemble_variable() with error "storage size > >> of <var> is unknown", > >> however no error is reported when compiled with -O2. > > > > Cf bug 24293 (for the -fsyntax-only case) - does this patch fix that? > Ah this doesn't fix PR24293, it seems analyze_function() doesn't get > called for -fsyntax-only. > I don't have a good solution for this. I assume varpool won't be > populated for -fsyntax-only ? > And we need to walk over decls with incomplete struct/union types > after parsing the whole translation unit. > In the attached patch, I kept a global vec<tree> incomplete_record_decls; > In finish_decl(), if the decl is static, has type struct/union and > size 0 then it is appened to incomplete_record_decls. > In c_parser_translation_unit(), iterate over incomplete_record_decls > and if report error if any decl has size zero. > The patch passes testsuite.
There's a GNU C extension allowing forward declarations of enums, and it seems that static enum e x; doesn't get diagnosed either with -fsyntax-only. Thus I think you should cover that case as well. -- Joseph S. Myers jos...@codesourcery.com