草庐IT

Clang-Format

全部标签

c++ - 为什么 GCC 在 Clang 不使用它的地方插入 mfence?

为什么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

c++ - "vtable"链接器错误(涉及带有 "=default"的虚拟析构函数)- Clang 3.1 中的潜在错误?

我的代码中出现链接器错误。我已将其精确定位为以下最基本的要点。这段代码给出了链接器错误"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的一部分。这可能是这个编译器中的错

c++ - 模板类中静态字段的初始化列表因 clang 而失败

以下代码片段在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

c++ - 为 clang 工具启用 RTTI?

我正在尝试使用clang的libTooling来构建一个基本的源到源转换工具。我想使用boost::regex和boost::filesystem,但链接到它们需要异常并启用RTTI。根据clangmailinglist,应该可以在不破坏任何东西的情况下启用RTTI。就是说,我找不到指示构建系统启用RTTI的设置或变量。(我正在使用cmake)。我可以将-frtti和-fexceptions标志添加到编译器命令,但clang构建系统正在添加它自己的-fno-rtti,-fno-exceptions标志似乎具有更高的优先级。 最佳答案

c++ - 使用 g++ 4.9.0 打包扩展失败,但适用于 clang++ 3.4

对于下面的代码:templatestructSet{};templateusingTail=Set;templatestructMemberOf;templatestructMemberOf>{staticconstexprboolvalue=true;};templatestructMemberOf>{staticconstexprboolvalue=false;};templatestructMemberOf>{staticconstexprboolvalue=false||MemberOf>::value;};g++4.9.0给出:ts.cpp:27:63:error:packe

c++ - 无法使用 clang 编译代码,但可以使用 gcc

我正在尝试修复一个开源C++项目中的一些错误,而原作者目前忙于他的学术生活而无法提供帮助。通过macports安装的gcc-4.9代码编译得很好。我一直在命令行上使用lldb进行调试。但是,如果可能的话,我希望使用clang编译代码,因为这样我可以同时使用Xcode和lldb并使错误更容易隔离。当我尝试使用clang编译代码时,出现以下错误:Infileincludedfrom./src/include/hash.h:25:./src/include/hash_stream.h:18:11:error:calltofunction'operator>>'thatisneithervis

c++ - LLVM/Clang 是否支持弱链接的 'weak' 属性?

简而言之:LLVM/Clang是否支持“弱”属性?我正在学习一些Arduino库源代码(更详细的是HardwareSerial.cpp),我发现了一些以前从未使用过的有趣属性weak:#ifdefined(HAVE_HWSERIAL0)voidserialEvent()__attribute__((weak));boolSerial0_available()__attribute__((weak));#endif我发现它很有趣,而且我读到如果未定义,链接器应将其设置为NULL。但是,在我使用Clang进行的测试中,我无法使用它。文件lib.cpp:#include"lib.h"#inc

c++ - g++ 和 clang++ SFINAE 和 SFINAE 失败的不同行为

C++11专家的几个问题。我正在与SFINAE打交道,我遇到了一个奇怪的情况,其中g++(4.9.2)和clang++(3.5.0)的行为不同。我准备了以下示例代码。很抱歉,我无法做到更简洁。#include#include#include#includetemplateclassfoo{private:templateusingenableIfIsInt=typenamestd::enable_if::value,R>::type;public:foo(){}templateenableIfIsIntbar(){std::cout).name()fl;foofi;fl.bar();f

c++ - 从它的另一个专业继承的模板可以是循环依赖还是 clang 的错误

考虑下面的代码:#include#include#includetemplatestructassign;templatestructassign,std::index_sequence>:assign,std::index_sequence>...{templateassign(TargetTuple&target,constSourceTuple&source):assign,std::index_sequence>(target,source)...{}};templatestructassign,std::index_sequence>{templateassign(Targe

c++ - 自定义转换运算符的 Clang 歧义

我一直在开发一种适配器类,当我在clang下遇到问题。当定义了左值引用和右值引用的转换运算符时,您会在尝试从您的类中移出时遇到歧义编译错误(当这样的代码应该没问题时,如operatorconstT&()const&仅允许用于左值AFAIK)。我用简单的例子重现了错误:#includeclassStringDecorator{public:StringDecorator():m_string("Stringdatahere"){}operatorconststd::string&()const&//lvalueonly{returnm_string;}operatorstd::strin