我不明白为什么Clang会拒绝以下代码:#include#includeconstchar*get_name(conststd::exception_ptreptr){returneptr.__cxa_exception_type()->name();}intmain(){}GCC没问题,但是Clang提示type_info是一个不完整的类型:$g++-4.7-std=c++0x-O3-Wall-Wextrat.cc-ot$clang++-3.2-std=c++0x-O3-Wall-Wextrat.cc-ott.cc:6:37:error:memberaccessintoincompl
我一直在MSVC2013中使用std::rbegin和std::rend。当我尝试使用GCC4.9.1或clang3.5.0编译我的代码时,两者都告诉我“rbegin”和“rend”是不是命名空间“std”的一部分。请参阅下面的代码示例。我是在做错什么,还是只是尚未在GCC和clang中实现?//test.cpp#include#include#includeintmain(int,char**){std::vectortest={1,2,3,4,5};for(autoit=std::rbegin(test);it!=std::rend(test);++it){std::cout海湾合
当new-expression的形式为new(std::nothrow)C;时,问题就出现了其中C是其构造函数抛出的类名。请参阅下面的代码和liveexample使用g++:#includevoid*operatornew(std::size_tsize,conststd::nothrow_t&)noexcept{void*p;p=malloc(size);std::coutg++打印以下内容,它似乎是正确的:operatornew(std::nothrow)C()operatordelete(std::nothrow)0x13f9c20exceptionthrowninC(int)w
VisualStudio2013编译器可以很好地处理以下代码,但clang5.0和6.2给我一个链接器错误:#includeusingnamespace::std;classIBase{public:virtualIBase&operator=(constIBase&other)=0;};classBase:virtualpublicIBase{public:Base&operator=(constIBase&other)override{constBase&b=dynamic_cast(other);return*this=b;}virtualBase&operator=(const
我按照官方手册中的描述在clang中实现了一个自定义属性:http://clang.llvm.org/docs/InternalsManual.html#how-to-add-an-attribute所以我在Attr.td中添加了以下代码:defMyAttr:InheritableAttr{letSpellings=[GNU,CXX11,GCC,Declspec];letSubjects=SubjectList;letDocumentation=[MyAttrDocs];}以及AttrDocs.td的文档。重建clang后,它显然知道该属性,因为我在使用它时没有收到未知属性警告。我什至
挠了挠脑袋3个多小时后,我终于放弃了,决定向你们求助。我有几个文件,它们将编译成一个可执行文件。使用-stdlib=libc++flag,我会得到/usr/include/c++/v1/string:1938:44:error:'basic_string'ismissingexceptionspecification'noexcept(is_nothrow_copy_constructible::value)'basic_string::basic_string(constallocator_type&__a)^/usr/include/c++/v1/string:1326:40:no
给定一个C++源代码,我想找到每个函数写入和读取的类字段。使用Clang前端执行此操作的最佳方法是什么?(我不要求对所有步骤进行详细解释;但是,作为一个有效解决方案的起点会很棒。)到目前为止,我尝试使用RecursiveASTVisitor解析语句,但很难跟踪节点连接。另外,我无法弄清楚如何跟踪以下内容:int&x=m_int_field;x++;这显然修改了m_int_field;但是给定一个Stmt是不可能知道的;所以AST遍历本身似乎不够。对我来说,一个好处是能够分别计算字段和子字段(例如,访问成员结构的三个字段)。示例:typedefstructY{intm_structfie
代码下面的代码给出了不同的输出,带有和不带有*注释的行:#include#includetemplateusingbool_void_t=void;templatestructis_complete:std::false_type{};templatestructis_complete>:std::true_type{};templatestructBase{staticconstexprboolvalue=is_complete{};//usingmagic=bool_void_t;//*};structFoo:Base{};intmain(){std::cout输出Thelinem
我正在使用clang静态分析器4.0.0。对于下面的例子intfun(){intaa=1,bb=0;intcc=aa/bb;//1)devidebyzero.//Reportedbyclangint*pt=nullptr;inta=*pt;//2)nullpointerdereference.//NOTReportedbyclangintb;intc=a+b;//3)Unusedinitialization.//Reportedbyclangreturncc;}Clang静态分析器仅报告两个问题1和3,并跳过问题2。而如果我像这样改变问题的顺序intfun(){int*pt=nullp
采用以下代码:#includeconstexprstd::arraya{};static_assert(std::next(std::begin(a))==std::begin(a)+1);使用-std=c++17GCC可以完美地编译它,但Clang会提示该表达式不是整型常量表达式。看起来问题出在std::next上,但是在C++17中应该是constexpr。尽管如此,std::next在std库中,而不是在编译器本身中,因此发生了一些奇怪的事情。为了让事情变得更好,如果您将-stdlib=libc++传递给Clang,该示例将完美编译。这是怎么回事?谁对谁错?编辑这个问题似乎与cl