[cfe-dev] Clang 2.7 and C++ support

Simone Pellegrini spellegrini at dps.uibk.ac.at
Tue Apr 20 01:02:22 PDT 2010


On 04/20/2010 09:25 AM, Douglas Gregor wrote:
> On Apr 20, 2010, at 12:03 AM, Simone Pellegrini wrote:
>
>    
>> Hi all,
>> I was wondering if C++ support will be enabled by default in this
>> release or we would have to wait the next release (2.8).
>>
>> and if not, is there any way to enable it?
>>      
> C++ support is enabled by default in 2.7.
>    
What I am doing is using clang as a library so I cannot use the clang 
driver directly.

I manually instantiate a CompilerInstance and feed C++ code and get the 
following error:

error: unknown type name 'class'

I also tried to feed the "-ccc-clang-cxx" flag as suggested in: 
http://clang.llvm.org/docs/UsersManual.html#cxx
but it didn't help.

The actual code I use to instantiate a compiler is the following:

CompilerInstance Clang;
Clang.setLLVMContext(new llvm::LLVMContext);
Clang.createDiagnostics(argc, argv);

Clang.setFileManager(&FileMgr);
Clang.createSourceManager();

Clang.InitializeSourceManager(File->getName());

// Add the default clang system headers
Clang.getHeaderSearchOpts().AddPath( 
"/software/llvm-2.7/lib/clang/1.1/include/", clang::frontend::System, 
true, false );
// add user headers
for (size_t i = 0; i < Flags::I_dirs.size(); ++i)
        Clang.getHeaderSearchOpts().AddPath( Flags::I_dirs[i], 
clang::frontend::Angled, true, false);

TargetOptions TO;
TO.Triple = llvm::Triple("x86_64", "PC", "Linux").getTriple();
Clang.setTarget( TargetInfo::CreateTargetInfo (Clang.getDiagnostics(), 
TO) );

// A compiler invocation object has to be created in order for the 
diagnostics to work
CompilerInvocation* CI = new CompilerInvocation; // CompilerInvocation 
will be deleted by CompilerInstance

const char* arg = "ccc-clang-cxx";
CompilerInvocation::CreateFromArgs(*CI, &arg, &arg+1, 
Clang.getDiagnostics());
Clang.setInvocation(CI);

Clang.createPreprocessor();
Clang.createASTContext();

...

what am I doing wrong? The code works perfectly for C programs!!

Where I can find the code

> 	- Doug
>    

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20100420/c677b039/attachment.html>


More information about the cfe-dev mailing list