[cfe-dev] extern "C" parsing

Douglas Gregor dgregor at apple.com
Wed Feb 17 23:30:30 PST 2010


On Feb 17, 2010, at 11:25 PM, Jay L. T. Cornwall wrote:

> Hi Doug,
> 
>>> The clang driver from SVN successfully parses this. My
>>> library-based interface to clang, however, gives this error:
>>> test.cpp:5:1: error: unknown type name 'MyStruct'
>>> The presence of an extern "C" {} block appears to hide the type. It
>>> parses correctly without the block. I have set
>>> LangOptions::CPlusPlus but have been unable to locate an option
>>> which controls this behaviour.
> 
>> That's very strange. CPlusPlus is the only option that should matter
>> here, because C++ name lookup involves looking into linkage
>> specifications.
> 
> I tracked this down in the end. With the -fsyntax-only parameter Clang parses the program correctly. With -parse-noop it gives the aforementioned error.
> 
> I believe this is because -parse-noop uses MinimalAction whereas -fsyntax-only invokes SyntaxOnlyAction. I traced the program error in the former case to MinimalAction::getTypeName failing to acknowledge MyStruct as a type name.

-parse-noop will never work for C++.

>> Perhaps we should step back a bit, however: how are you setting up
>> your library interface to Clang? Are you using
>> CompilerInstance/CompilerInvocation
> 
> Initially I had followed this tutorial:
> 
> http://amnoid.de/tmp/clangtut/tut.html
> 
> This information appears to be quite outdated now. I subsequently remodelled our application to Clang to use the CompilerInstace/CompilerInvocation interface and this now works.

Yes, that's out of date. We're hoping to find time to write a good tutorial for CompilerInstance/CompilerInvocation.

> With Clang successfully parsing a complex C++ file (with many deep Boost MPL-based templates and other magic) I now have access to the ASTContext to begin porting our semantic analyses. The (speed/memory) performance issues we had with ROSE have gone away with Clang. You guys have done some nice work!

Thanks, glad to hear it!

	- Doug



More information about the cfe-dev mailing list