[llvm-dev] type_traits conflict with gcc4.9

LING Zhipeng via llvm-dev
Wed, 20 Jan 2016 01:59:38 -0000

I have install llvm from source code.and set eviroment path:

export LLVM_DIR=/opt/llvm/llvm-3.7.0.src/install/share/llvm/cmake
export PATH=$PATH:/opt/llvm/llvm-3.7.0.src/install/bin
export C_INCLUDE_PATH=/opt/llvm/llvm-3.7.0.src/install/lib/clang/3.7.0/include
export
CPLUS_INCLUDE_PATH=/opt/llvm/llvm-3.7.0.src/install/lib/clang/3.7.0/include
export LIBRARY_PATH=/opt/llvm/llvm-3.7.0.src/install/lib/clang/3.7.0/lib/linux
export
LD_LIBRARY_PATH=/opt/llvm/llvm-3.7.0.src/install/lib/clang/3.7.0/lib/linux

But when I make some example ,always report below erro:


linux-c0ik:/opt/llvmwork/example3 # make
/opt/llvm/llvm-3.7.0.src/install/bin/clang++
-I/opt/llvm/llvm-3.7.0.src/install/include  -fPIC -fvisibility-inlines-hidden
-Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual
-Wno-missing-field-initializers -pedantic -Wno-long-long
-Wno-maybe-uninitialized -Wno-comment -std=c++11 -ffunction-sections
-fdata-sections -O3 -DNDEBUG -fno-exceptions -fno-rtti  -D_GNU_SOURCE
-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -fno-rtti
-c -o main.o main.cpp
warning: unknown warning option '-Wno-maybe-uninitialized'; did you mean
'-Wno-uninitialized'? [-Wunknown-warning-option]
In file included from main.cpp:2:
In file included from
/opt/llvm/llvm-3.7.0.src/install/include/clang/Basic/VirtualFileSystem.h:16:
In file included from
/opt/llvm/llvm-3.7.0.src/install/include/clang/Basic/LLVM.h:22:
In file included from
/opt/llvm/llvm-3.7.0.src/install/include/llvm/Support/Casting.h:19:
In file included from
/opt/llvm/llvm-3.7.0.src/install/include/llvm/Support/type_traits.h:17:
/usr/lib/gcc/i586-suse-linux/4.9/../../../../include/c++/4.9/type_traits:1371:66:
error: incomplete type 'clang::Decl' used in type trait expression
    : public integral_constant<bool, __is_base_of(_Base, _Derived)>
                                                                 ^
/opt/llvm/llvm-3.7.0.src/install/include/llvm/Support/Casting.h:63:44: note: in
instantiation of template class 'std::is_base_of<clang::VarDecl,
clang::Decl>'
      requested here
    To, From, typename std::enable_if<std::is_base_of<To,
From>::value>::type> {
                                           ^
/opt/llvm/llvm-3.7.0.src/install/include/llvm/Support/Casting.h:96:12: note:
during template argument deduction for class template partial specialization
      'isa_impl<type-parameter-0-0, type-parameter-0-1, typename
enable_if<std::is_base_of<To, From>::value, void>::type>'
      [with To = clang::VarDecl, From = clang::Decl]
    return isa_impl<To, From>::doit(*Val);
           ^
/opt/llvm/llvm-3.7.0.src/install/include/llvm/Support/Casting.h:122:36: note: in
instantiation of member function 'llvm::isa_impl_cl<clang::VarDecl, const
clang::Decl
      *>::doit' requested here
return isa_impl_cl<To,FromTy>::doit(Val);
                                   ^


My example src file:

#include "clang/Basic/VirtualFileSystem.h"
#include "clang/Basic/TargetOptions.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/SourceManager.h"
#include "clang/AST/DeclGroup.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/Parse/ParseAST.h"
#include "clang/Frontend/CompilerInstance.h"


//using namespace clang;
class CustomASTConsumer : public clang::ASTConsumer {
public:
CustomASTConsumer () : ASTConsumer() { }
virtual ~ CustomASTConsumer () { }
virtual bool HandleTopLevelDecl(clang::DeclGroupRef decls)
{
int i=0;
clang::DeclGroupRef::iterator it;
for( it = decls.begin(); it != decls.end(); it++)
{
clang::VarDecl *vd = llvm::dyn_cast<clang::VarDecl>(*it);
if(vd)
    i++;
/*std::cout << vd->getDeclName().getAsString() << std::endl;;*/
}
return true;
}
};

int main() {
clang::CompilerInstance ci;
ci.createDiagnostics();
std::shared_ptr<clang::TargetOptions> to(new clang::TargetOptions())/*=new
clang::TargetOptions()*/;

/*clang::TargetOptions to;*/
to->Triple = llvm::sys::getDefaultTargetTriple();
clang::TargetInfo *tin ;
//clang::TargetInfo.getTargetOpts();
   tin=clang::TargetInfo::CreateTargetInfo(ci.getDiagnostics(),to);
ci.setTarget(tin);
ci.createFileManager();
ci.createSourceManager(ci.getFileManager());
ci.createPreprocessor(clang::TU_Complete);
ci.createASTContext();
std::unique_ptr<clang::ASTConsumer> astConsumer(new clang::ASTConsumer()/*
CustomASTConsumer ()*/);
/*CustomASTConsumer *astConsumer = new CustomASTConsumer ();*/

ci.setASTConsumer(std::move(astConsumer));
const clang::FileEntry *file = ci.getFileManager().getFile("hello.c");

ci.getSourceManager().createFileID(file,clang::SourceLocation(),clang::SrcMgr::C_User);
/*ci.getSourceManager().createMainFileID(file);*/
ci.getDiagnosticClient().BeginSourceFile(
ci.getLangOpts(), &ci.getPreprocessor());

/*clang::ParseAST(ci.getPreprocessor(), astConsumer, ci.getASTContext());*/
clang::ParseAST(ci.getSema(),ci.getFrontendOpts().ShowStats,
ci.getFrontendOpts().SkipFunctionBodies);

ci.getDiagnosticClient().EndSourceFile();
return 0;
}

My example makefile:
RTTIFLAG := -fno-rtti
CXXFLAGS := $(shell llvm-config --cxxflags) $(RTTIFLAG)
LLVMLDFLAGS := $(shell llvm-config --ldflags --libs)
#DDD := $(shell echo $(LLVMLDFLAGS))
SOURCES = main.cpp
OBJECTS = $(SOURCES:.cpp=.o)
EXES = $(OBJECTS:.o=)
CLANGLIBS = \
-L /opt/llvm/llvm-3.7.0.src/install \
-lclangFrontend \
-lclangParse \
-lclangSema \
-lclangAnalysis \
-lclangAST \
-lclangLex \
-lclangBasic \
-lclangDriver \
-lclangSerialization \
-lLLVMMC \
-lLLVMSupport \
all: $(OBJECTS) $(EXES)
%: %.o
$(CXX) -o $@ $< $(CLANGLIBS) $(LLVMLDFLAGS)
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20160120/0749a9cf/attachment-0001.html>