Clang 2.7 and C++ support

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?

cheers, Simone

Hi Simone,

You can use clang++ just like g++.

C++ support is enabled by default in 2.7.

  - Doug


  
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

I don’t see where you’re setting the LangOption bit that tells it to compile C++ code.

  • Doug