草庐IT

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

c++ - Clang 无法从基类中找到 const 模板成员函数

以下C++文件:structBase{templatevoidf(T&&)const{}};structDerived:Base{templatevoidf(T&&)const{}usingBase::f;};intmain(){Derivedconstcd;cd.f('x');}用GCC编译得很好,但用Clang编译不好:$g++-7.3.0-std=c++11test.cpp-otest-Wall-Wextra$g++-7.2.0-std=c++11test.cpp-otest-Wall-Wextra$g++-6.4.0-std=c++11test.cpp-otest-Wall-W

c++ - 为什么 GCC 会为结构化绑定(bind)诊断未使用的变量而 Clang 不会?

让我们从一个最小的例子开始:#includeintmain(){auto[a,b]=std::pair(1,'A');returna;}使用GCC7.3编译传递-std=c++17和-Wunused-variable,并运行它::Infunction'intmain()'::5:15:warning:unusedvariable'b'[-Wunused-variable]auto[a,b]=std::pair(1,'A');^GCC可能会正确地报告未使用b,但它错误地将其称为变量。引用[dcl.struct.bind]/1:Astructuredbindingdeclarationin

c++ - 带有 libc++ 异常的 Clang

我一直在试验不同的C++库,并发现了以下内容:简单的应用:#includeintmain(intargc,char*argv[]){try{throw1;}catch(...){std::cout当我像这样在ARM上编译它时:clang++-stdlib=stdlibc++如预期的那样捕获了异常。但是当我把它改成:clang++-stdlib=libc++我不断得到:terminatingwithuncaughtexceptionoftypeintAborted我尝试使用各种标志显式打开异常,例如:-fexceptions-fcxx-exceptions-frtti但是这些标志都不起作