[cfe-dev] clang_parseTranslationUnit2 passes on incomplete type error

Jiri Olsa via cfe-dev cfe-dev at lists.llvm.org
Mon Apr 29 05:14:08 PDT 2019


On Mon, Apr 29, 2019 at 01:48:42PM +0200, Milian Wolff wrote:
> On Thursday, April 18, 2019 3:14:46 PM CEST Jiri Olsa via cfe-dev wrote:
> > hi,
> > when using clang_parseTranslationUnit2 to compile uncomplete
> > struct declaration, like:
> > 
> >   struct a {
> >     int a;
> >     int b;
> >     struct c c;
> >   };
> > 
> > I'm getting just warning on terminal but no error on the call itself:
> > 
> >   $ ./test
> >   definitions.h:1:35: error: field has incomplete type 'struct c'
> >   definitions.h:1:33: note: forward declaration of 'struct c'
> >   Clang error 0
> >
> > Is there a way (some flag perhaps) to make this fail on this input,
> > or do I need to call clang_visitChildren and check the fields offsets
> > and sizes, because those seem mangled, offsets are zero and size -2.
> > 
> > I'm new to this, so I might be missing something obvious ;-)
> 
> Hey Jirka,
> 
> I think clang_parseTranslationUnit2 only returns an error when something 
> seriously failed. But it won't return an error on "normal" source input 
> errors. Instead, you'll get diagnostics for those. So in your case, I suggest 
> you iterate over the diagnostics (cf. clang_getNumDiagnostics and  
> clang_getDiagnostic), then check clang_getDiagnosticSeverity for every 
> diagnostic and error-our when you encounter an error.

ok, I was hoping for some magical flag to force it that I overlooked ;-)
I'll check on the diagnostics iteration then

thanks,
jirka



More information about the cfe-dev mailing list