考虑以下代码片段:voidf();voida(){f();}voidb()noexcept{f();}在上面的场景中,f的主体对于当前翻译单元中的编译器是不可见的。因此,由于b被标记为noexcept,必须在调用方生成额外的代码以确保异常被捕获并且std::terminate被调用。这就是clang++-Ofast-std=c++2a所做的(主干版本):a():#@a()jmpf()#TAILCALLb():#@b()pushraxcallf()popraxretmovrdi,raxcall__clang_call_terminate__clang_call_terminate:#@_
下面的代码适用于gcc-4.8.2#includeusingnamespacestd;templatevoidfunc(Args...args,intoptional=0){cout(3.3f);//Fine,prints'0'func();//gccOK,failstocompilewithclang-3.5}它输出:$./a.out1200但是如果用clang-3.5编译失败,test_variadic.cpp:15:2:error:nomatchingfunctionforcallto'func'func();^~~~test_variadic.cpp:5:6:note:cand
GCC和clang不同意此代码。#includetemplatetypenameTpl>structstorage{usingtype_t=T;templateusingstorage_tpl=Tpl;};templatetypename>structF{constexprstaticintx=1;};templatestructF{constexprstaticintx=2;};intf(){usingS=storage;static_assert(F().x==2);returnF().x;}根据clangS::storage_tpl不是std::void_t;结果它选择了主模板F
我正在使用travis.ci对我的git存储库进行自动化测试构建。对于Linux,他们使用:Ubuntu12.04使用clang3.4根据clangpageClang3.4支持所有C++14语言功能(只要您使用-std=c++1y标志)。到目前为止一切顺利:我还需要使用std::index_sequence这是图书馆的特色N3658不是语言功能。但是我找不到任何关于为clang更新C++标准库以确保支持此功能的特定文档(不支持开箱即用)。测试代码:#includeintmain(){std::index_sequenceseq;}测试构建:>clang++-std=c++1ypl.cp
最近Whydoesaconstobjectrequiresauser-provideddefaultconstructor?被标记为WhydoesC++requireauser-provideddefaultconstructortodefault-constructaconstobject?的拷贝.我正在使用coliru和rextexter测试不同版本的gcc(g++-4.7、g++-4.8、g++-4.9)和clang(3.4和3.5),看看新版本的编译器是否引入了这种行为。这里我们有两个测试用例,分别来自两个问题:classA{public:voidf(){}};intmain(
templatestructA{};voidfunc();Aa;//sameresultwithAa;此代码使用Clang(包括最新的8.0.0)编译,但不能使用GCC(包括最新的9.1)编译。GCC说:错误:'void()'不是模板非类型参数的有效类型哪个编译器是正确的,为什么?更新我猜GCC是错误的,因为以下代码在Clang和GCC上都可以编译:templatestructA{};voidfunc();Aa;//sameresultwithAa;因此与GCC在第一个示例中的报告相反,void()似乎是“模板非类型参数的有效类型” 最佳答案
使用C++17auto模板参数我遇到了另一个g++/clang++分歧。给定以下简单代码templatestructfoo;templatestructfoo{};intmain(){foof42;//我看到clang++(8.0.0,例如)编译g++(9.2.0,例如)给出以下错误的代码prog.cc:Infunction'intmain()':prog.cc:12:13:error:aggregate'foof42'hasincompletetypeandcannotbedefined12|foof42;|^~~如果我们使用int常量而不是long常量,两个编译器都会编译foof4
对于这样的代码:typedefenumFooEnum:intFooEnum;enumFooEnum:int{A=1,B};clang(linux/7.0.0)报告没有错误[-c-std=c++11-pedantic],但是gcc(linux/8.2.1)不编译它:g++-c-std=c++11-pedantictest2.cpptest2.cpp:1:28:error:expected';'or'{'before'FooEnum'typedefenumFooEnum:intFooEnum;^~~~~~~test2.cpp:1:28:error:expectedclass-keybefo
这是测试代码templatevoidf(){Tt;t.f(0);//compilesevenwithoutthe"template"keyword,whatamImissing?}classabc{public:templatevoidf(int){}};intmain(){f();}我正在使用g++4.4.6。谢谢P.S:我已经大大编辑了我的问题。请不要介意。编辑:我向EDG的人问了这个问题,这是MikeHerrick不得不说的Wedodiagnosethisasanerrorin--strictmodeaswellasanymodethatenablesdependentnamel
我有一些(遗留)代码是我第一次使用clang构建的。代码是这样的:sprintf(buf,"%s",p1,p2);Clang给出以下警告(-Werror错误):test.c:6:33:error:trigraphconvertedto'}'character[-Werror,-Wtrigraphs]sprintf(buf,"%s",p1,p2);^显然??>不是三字母组,所以我想完全禁用三字母组(源代码没有故意在任何地方使用它们)。我已经尝试过-no-trigraphs但这不是一个真正的选择:clang:warning:argumentunusedduringcompilation:'