草庐IT

clang-omp

全部标签

c++ - 这段编译良好的荒谬代码是 Clang 和 GCC 中的错误吗?

这个问题在这里已经有了答案:Injectedclassnamecompilerdiscrepancy(3个答案)关闭6年前。我今天在研究模板,看看能否让编译器从其内部类之一推断出外部类的类型。我没有找到我的解决方案(我怀疑这是不可能的),但是在尝试修复错误时我遇到了非常奇怪的行为,我将其简化为以下代码片段。structA{structB{};templatestructEverythingIsFine{usingOuter=T;usingInner=typenameT::B::B::B::B::B::B;};usingItWillBeOkay=EverythingIsFine;//Pr

c++ - clang 无法在模板实例化时生成默认的移动构造函数

下面的代码(我无法制作更短的MVCE)unit.h:#includetemplatestructfoo{std::vectordata;foo(foo&&)=default;//noassemblygeneratedfoo(std::vector&&v):data(std::move(v)){}};externtemplatestructfoo;//indicatestemplateinstantiationelsewhereunit.cc:#include"unit.h"templatestructfoo;//forcestemplateintantiationma​​in.cc:#

c++ - clang 中 regex_constants 的错误实现?

如standard中所述:match_prev_avail:--first是一个有效的迭代器位置。设置后,会导致match_not_bol和match_not_bow被忽略但我运行以下代码并得到:#include#includeusingnamespacestd;intmain(){regexre0("^bcd");stringstr="abcd";std::string::iteratorstart=str.begin()+1;cout输出:010match_prev_avail似乎被match_not_bol覆盖了。 最佳答案

c++ - clang 的扫描构建不适用于简单的 cpp 文件

我无法让clang的c++-analyzer处理玩具C++文件。#includeusingnamespacestd;intmain(){intt[4];intx,y;t[5]=1;if(x)y=5;x=t[y];}makefile就是all:t.cpp$(CXX)t.cppscan-buildmake输出:scan-build:'clang'executablenotfoundin'/usr/share/clang/scan-build/bin'.scan-build:Using'clang'frompath:/usr/bin/clang/usr/share/clang/scan-bu

c++ - 使用 GCC 编译模板友元错误,但不使用 clang

此代码使用clang3.7.1编译(没有诊断),但使用GCC5.3.0编译失败>(liveexample):#includetemplatestructA{voidfoo(){static_cast(this)->implementation();}};structCrtp:A{templatefriendstructA;private:voidimplementation(){std::coutGCC的错误信息如下:main.cpp:13:16:error:specializationof'A'afterinstantiationfriendstructA;哪个是正确的,为什么?是G

c++ - Clang claims that `member reference base type ' X' is not a structure or union`,但 X 是具有推导参数的结构模板

考虑以下代码:templatestructX{X(T){}voidfoo(){}};templatestructY{intobject=0;voidbar(){X(object).foo();}};Liveongcc.godbold.orgGCC8.2编译它,而Clang7吐出以下错误::13:18:error:memberreferencebasetype'X'isnotastructureorunionX(object).foo();~~~~~~~~~^~~~这对我来说像是一个错误。条件非常具体:如果任一结构不是模板,或者object不是成员变量,或者不涉及CTAD(类模板参数推导

c++ - gcc vs clang 在具有可变参数和相同类型的额外参数的部分特化上的行为

以下代码:#includetemplatestructA{};templatestructA{};intmain(){Aa0;Aa2;return0;}...不编译g++(版本5.1.0和5.3.0)由于:error:partialspecializationisnotmorespecializedthantheprimarytemplatebecauseitreplacesmultipleparameterswithapackexpansion...但使用clang编译.是否允许声明这样的部分特化?旁注:实际上,自A以来,特化是危险的两个编译器都无法编译(模板参数数量错误)。

c++ - 具有非 constexpr 构造函数的 constexpr 非静态成员函数(gcc、clang 不同)

对于这段代码:structS{S(intm):m(m){}constexprintf()const{returnm;}intm;};intmain(){Ss(1);}它由clang3.6、3.7和3.8使用-std=c++14编译,没有警告或错误。但在g++5.x中出现以下错误:main.cpp:4:19:error:enclosingclassofconstexprnon-staticmemberfunction'intS::f()const'isnotaliteraltypeconstexprintf()const{returnm;}^main.cpp:1:8:note:'S'is

c++ - 这被认为是有效的 c++11 或 c++14 吗?还是 gcc/clang 弄错了?

在尝试解决IsitpossibletotellifaclasshashiddenabasefunctioninC++?时,我生成了这个:#include#include#defineENABLE_IF(...)std::enable_if_t=0template::value)>autohas_x_f(T*)->std::true_type;templateautohas_x_f(B*)->std::false_type;templateusinghas_x=decltype(has_x_f((T*)nullptr));templatestructA{voidx(){}staticco

c++ - 为什么使用 clang -std=gnu++11 时此 C++ 代码会编译?

使用clang-std=gnu++11-ctest.cpp编译:voidtest(){[[randomtexthere]]if(0){}}但这会产生错误main.cpp:3:1:error:expectedstatement:voidtest(){[[randomtexthere]]}如果我使用clang-std=gnu++11-S-emit-llvmmain.cpp编译并查看LLVM代码,它看起来像[[...]]行无效:definevoid@_Z5testv()nounwinduwtablessp{retvoid}有什么想法吗?错误或某些C++11语法或GNU扩展语法?我正在使用Xc