草庐IT

clang_complete

全部标签

c++ - 在 Windows 上使用 clang 编译 CUDA 时的重新定义

尽管question几乎相同已经问过,答案是针对OSX的,不再适用(而且真的很老套)。问题是在Windows上用clang编译cuda时,math_functions.hpp中有大量重定义。通过一些调查,显然cuda决定将其math_functions.hpp和math_functions.h函数放在namespacestd中(这是否合法??),并与cmath中的所有libstdc++函数和clang自己用于编译cuda的头文件发生冲突。我该如何处理?最好不要使用上一个问题中显示的hacky方式?旁注根据clang的documentation,clang可以基于__global__/_

c++ - 自动非类型模板参数 : ambiguous partial specializations in Clang

Clang(7,8,trunk)拒绝以下代码enumclassE{};inlinestaticconstexprautoe=E{};//inlinestaticconstexprautoe=nullptr;templateclassS;templateclassS{};templateclassS{};intmain(){Ss;}出现错误:error:ambiguouspartialspecializationsof'S'note:partialspecializationmatches[witha=0,b=0]templateclassS{};^note:partialspecial

c++ - 如何使用 Clang 从 C++ 字符串生成 AST?

我正在尝试使用Clang来操作C++源代码,但我在发现API时遇到了问题。我想获取一串C++源代码并从中生成一个AST;类似于:automyAst=clang::parse("autox=1+1;");有这方面的最小工作示例吗? 最佳答案 你可以试试下面的代码:std::unique_ptrAST(tooling::buildASTFromCode("autox=1+1;"));TranslationUnitDecl*DC=AST->getASTContext().getTranslationUnitDecl();if(DC){ll

C++ std::vector initializer_list 重载歧义 (g++/clang++)

考虑以下代码:#include#defineBROKENclassVar{public:#ifdefBROKENtemplateVar(Tx):value(x){}#elseVar(intx):value(x){}#endifintvalue;};classClass{public:Class(std::vectorarg):v{arg}{}std::vectorv;};无论BROKEN是否被定义,Clang++(7.0.1)编译它没有错误,但是如果BROKEN被定义,g++(8.2.1)会引发错误:main.cpp:9:20:error:cannotconvert‘std::vect

c++ - 无法通过 Clang API 找到标识符,但 Clang 在使用时可以找到它

我正在Clang解析的C++源文件中查找标识符。这是一个带有五个参数的函数,这些参数在源文件(而不是标题)中声明。当我试图用一个参数调用它时,Clang给出了一个适当的错误——甚至是函数声明的全文。但是当我尝试使用API查找它时,Clang坚持认为它不存在。相关代码如下:llvm::LLVMContextc;clang::CompilerInstanceCI;llvm::Modulem("",c);clang::EmitLLVMOnlyActionemit(&c);emit.setLinkModule(&m);std::stringerrors;llvm::raw_string_ost

c++ - 在 clang 中返回 std::initializer_list

这个问题在这里已经有了答案:lifetimeofastd::initializer_listreturnvalue(2个答案)关闭7年前。考虑这个代码示例:#include#includeintmain(){for(autoe:[]()->std::initializer_list{return{1,2,3};}())std::cout我尝试用g++编译它(gcc版本4.9.2(Debian4.9.2-10))并且输出是正确的。在clang++(Debianclangversion3.5.0-9(tags/RELEASE_350/final)(basedonLLVM3.5.0))中输出

c++ - 在 clang 中强制使用 `const char[]` 字符串文字

编译以下代码voidf(char*,constchar*,...){}voidf(constchar*,...){}intmain(){f("a","b");}用clang给我这个错误:prog.cpp:6:2:error:callto'f'isambiguousf("a","b");^prog.cpp:1:6:note:candidatefunctionvoidf(char*,constchar*,...){}^prog.cpp:2:6:note:candidatefunctionvoidf(constchar*,...){}^AFAIK字符串字面量在C++中是常量,因此重载规则应该

c++ - 关于表达式副作用的 Clang 警告

给定以下源代码:#include#includestructBase{virtual~Base();};structDerived:Base{};intmain(){std::unique_ptrptr_foo=std::make_unique();typeid(*ptr_foo).name();return0;}并编译它:clang++-std=c++14-Wall-Wextra-Werror-Wpedantic-g-otesttest.cpp环境设置:linuxx86_64clangversion5.0.0由于警告(注意-Werror),它无法编译:error:expression

c++ - clang 静态分析器是否因从 unique_ptr 列表中弹出前面而感到困惑?

以下C++11代码是我认为会在clang中触发误报的最小示例:#include#include#includeclassElementType{};intmain(intargc,constchar*argv[]){std::list>theList(5);theList.pop_front();for(constauto&element:theList){//(*)std::cout在标有星号(*)的行上,clang分析器声明...filePath.../main.cpp:21:29:Useofmemoryafteritisfreed(withinacallto'begin')就我的

c++ - 自动模板参数 : g++ 7. 3 vs clang++ 6.0 : Which compiler is correct?

对于这个代码示例,两个编译器会产生不同的结果。Clang生成两种不同的类型。G++对fu和fi使用相同的类型。哪个符合标准?#includetemplatestructfoo{decltype(IVAL)x=-IVAL;};intmain(){foofu;foofi;std::coutg++-7.3输出:42949672864294967286clang-6.0输出:-104294967286 最佳答案 gcc在这里是错误的,这显然是两种不同的类型。并确认-此错误已在gcc8.0.1中修复Samplecode