[cfe-dev] clang_parseTranslationUnit2 passes on incomplete type error

Jiri Olsa via cfe-dev cfe-dev at lists.llvm.org
Mon Apr 29 04:02:37 PDT 2019


hi,
trying it once more.. any idea? ;-)

thanks,
jirka


On Thu, Apr 18, 2019 at 03:14:46PM +0200, 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 ;-)
> 
> thanks,
> jirka
> 
> 
> ---
> #include <clang-c/Index.h>
> #include <iostream>
> #include <vector>
> 
> using namespace std;
> 
> int main(int argc, char **argv)
> {
> 	CXIndex index = clang_createIndex(1, 1);
> 	CXErrorCode error;
> 	CXTranslationUnit translation_unit;
> 	std::string input = "struct a { int a; int b; struct c c; };";
> 
> 	CXUnsavedFile unsaved_files[] =
> 	{
> 		{
> 			.Filename = "definitions.h",
> 			.Contents = input.c_str(),
> 			.Length = input.size(),
> 		},
> 	};
> 
> 	error = clang_parseTranslationUnit2(
> 			index,
> 			"definitions.h",
> 			NULL, 0,
> 			unsaved_files, sizeof(unsaved_files)/sizeof(CXUnsavedFile),
> 			CXTranslationUnit_DetailedPreprocessingRecord,
> 			&translation_unit);
> 
> 	cerr << "Clang error " << error << endl;
> 	return 0;
> }


More information about the cfe-dev mailing list