我的图书馆doctest在travisCI上使用200多个构建进行测试-x86/x64调试/发布linux/osx和广泛的编译器-从gcc4.4到6和clang3.4到3.8我所有的测试都是通过valgrind和地址sanitizer(也是UBsanitizer)运行的。我最近发现并非ASAN的所有功能都默认启用-例如:check_initialization_order=truedetect_stack_use_after_return=truestrict_init_order=true所以我启用了它们并开始收到如下例代码的错误。int&getStatic(){staticintd
挠了挠脑袋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
为什么GCC和Clang会为此代码(x86_64,-O3-std=c++17)生成如此不同的asm?#includeintglobal_var=0;intfoo_seq_cst(inta){std::atomicia;ia.store(global_var+a,std::memory_order_seq_cst);returnia.load(std::memory_order_seq_cst);}intfoo_relaxed(inta){std::atomicia;ia.store(global_var+a,std::memory_order_relaxed);returnia.loa
我有以下代码:typedefintAliasB;typedefunsignedshortAliasA;classAlias{public:explicitAlias(intsomeInt){}};//(*)!!belowbreakstheconversionpathviaAliasA!!//typedefAliasAliasA;classC{public:C(){}};classB{public:B(){}B(constAliasB&value){}operatorAliasB()const{return-1000;}Ccombine(constB&someB){returnC();}
我的代码中出现链接器错误。我已将其精确定位为以下最基本的要点。这段代码给出了链接器错误"vtableforFoo",referencedfrom:Foo::Foo()classFoo{public:Foo();virtual~Foo()=default;};Foo::Foo(){}但是这段代码没有给出任何错误:classFoo{public:Foo();virtual~Foo(){}};Foo::Foo(){}为什么?我认为=default基本上应该和那些空方括号做同样的事情。更新:我正在使用“AppleLLVM编译器4.1”,它是Xcode4.5.2的一部分。这可能是这个编译器中的错
以下代码片段在g++和clang++下运行良好://bsp1.ccclassA{public:A(int,charconst*);intvalue;constchar*name;};classB{public:staticconstAmany_as[];};AconstB::many_as[]{{0,"zero"},{1,"one"},{2,"two"},{3,"three"},{77,0}};当我更改要模板化的类B时://bsp2.ccclassA{public:A(int,charconst*);intvalue;constchar*name;};templateclassB{pu