草庐IT

c++ - clang 或 gcc 关于此内部类成员访问是否正确?

以下代码在clang上编译和工作,但在gcc上失败并显示“错误:非静态数据成员‘Outer::a’的无效使用”:#include#include#include#include#includeclassOuter{public:boola=false;virtualvoidf()=0;templateclassInner:publicT{public:virtualvoidf()override{a=true;//Note:accessedthroughinheritance,notthroughouterscope}};};structFoo:Outer{};intmain(){Ou

c++ - clang 忽略属性 noinline

我希望__attribute__((noinline))在添加到函数时确保该函数被触发。这适用于gcc,但clang似乎仍将其内联。这是一个例子,你也可以openonGodbolt:namespace{__attribute__((noinline))intinner_noinline(){return3;}intinner_inline(){return4;}intouter(){returninner_noinline()+inner_inline();}}intmain(){returnouter();}当使用-O3构建时,gcc发出inner_noinline,但不是inner

c++ - clang 的 -fcatch-undefined-behavior 没有像宣传的那样工作

我构建了llvm/compiler-rt/clang的3.1版本,我正在尝试查看-fcatch-undefined-behavior是否真的有任何作用。到目前为止,没有运气。例如。我编译运行#include#includeintmain(){int*x=malloc(sizeof(int)*10);printf("%d\n",x[20]);return0;}与$/usr/local/bin/clang-fcatch-undefined-behaviorundef_test.c&&./a.out0我是不是漏掉了一些非常简单的东西? 最佳答案

c++ - clang 的 libc++ 产品准备好了吗?

按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visitthehelpcenter指导。关闭10年前。有没有人在生产中使用clang的libc++有积极的经验?状态图在http://libcxx.llvm.org/libcxx_by_chapter.pdf我觉得不太好。

c++ - 如何使用 C API 而不是实际知道 Clang 的书面 var 类型?

我正在尝试通过CAPI使用Clang,详细索引。问题是某些类型不是按编写的那样返回,而是按编译器返回。例如“Stream&”变成“int&”,“byte”变成“int”。一些测试库://TODOmakeitasubclassofagenericSerial/StreambaseclassclassFirmataClass{public:FirmataClass(Stream&s);voidsetFirmwareNameAndVersion(constchar*name,bytemajor,byteminor);我正在使用代码获取方法信息:voidshowMethodInfo(const

c++ - Clang 和 GCC 误推模板参数

我不擅长C++,所以这可能是一个新手错误。我正在尝试制作一个异构链表类型,其中每个节点的类型和列表其余部分的类型在每个节点中都是已知的。这是一个SSSCE:#includetemplatestructhnode{Tdata;hnode*next;};templatestructhnode{Tdata;std::nullptr_tnext;};templatehnodehcons(T&&val,std::nullptr_t){return{std::forward(val),nullptr};}templatehnodehcons(T&&val,hnode&next){return{st

c++ - 如何从 clang AST 节点打印源位置

我正在松散地遵循http://clang.llvm.org/docs/LibASTMatchersTutorial.html上的教程.我设法创建了一个匹配类定义的AST匹配器,我的MatchFinder看起来像这样classClassDeclPrinter:publicMatchFinder::MatchCallback{public:virtualvoidrun(constMatchFinder::MatchResult&result)override{if(clang::NamedDeclconst*nd=result.Nodes.getNodeAs("id")){nd->dump

c++ - 为什么我收到 clang 警告 : no previous prototype for function 'diff'

我的代码中有以下声明://Centraldifffunction,makestwofunctioncalls,O(h^2)REALdiff(constREALh,constREALx,REAL(*func)(constREAL)){//diff=f(x+h)-f(x-h)/2h+O(h^2)return((*func)(x+h)-(*func)(x-h))/(2.0*h+REALSMALL);}这在“utils.h”文件中。当我使用它编译测试时,它会给我:clang++-Weverythingtests/utils.cpp-otests/utils.oInfileincludedfro

c++ - 在 clang 中实例化后的静态成员初始化

此类代码可以通过GCC编译,但clang3.5失败。#includeusingnamespacestd;templateclassC{public:conststaticintx;};intmain(){cout::x;}templateconstintC::x=4;Clang返回消息:hello.cpp:15:19:error:explicitspecializationof'x'afterinstantiationconstintC::x=4;^hello.cpp:11:19:note:implicitinstantiationfirstrequiredherecout::x;^是

c++ - 使用替换的 operator new 进行 Clang 链接时优化会导致 valgrind 中的 free()/delete 不匹配

当将clang3.5.0与-flto一起使用并与共享库链接时,似乎在共享库中调用operatordelete不遵循与调用相同的符号解析顺序来自主要对象的code>operatornew。示例:共享.cpp:voiddeleteIt(int*ptr){deleteptr;}ma​​in.cpp:#include#includevoid*operatornew(size_tsize){void*result=std::malloc(size);if(result==nullptr){throwstd::bad_alloc();}returnresult;}voidoperatordelet