[cfe-dev] extern "C" parsing
Douglas Gregor
dgregor at apple.com
Wed Feb 17 15:49:38 PST 2010
On Feb 16, 2010, at 8:11 AM, Jay L. T. Cornwall wrote:
> Hi,
>
> I am porting one of our internal tools built upon the ROSE
> source-to-source compiler to LLVM/Clang, to improve its scalability.
>
> With the program:
>
> extern "C" {
> typedef struct {} MyStruct;
> }
>
> MyStruct a;
>
> 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.
> Could you point me in the right direction?
I'm not sure where to point you. The lookup code in question is Sema::LookupName (in lib/Sema/SemaLookup.cpp). I guess you could make sure that it's performing C++ name lookup when it looks for 'MyStruct'.
Perhaps we should step back a bit, however: how are you setting up your library interface to Clang? Are you using CompilerInstance/CompilerInvocation?
- Doug
More information about the cfe-dev
mailing list