草庐IT

c++ - Clang 修改析构函数中的返回值?

在尝试编写一个类来计时调用它的构造函数和析构函数之间的持续时间时,我遇到了我认为是clang中的错误。(编辑:这不是错误;它是实现定义的复制省略)下面的timer结构保留指向作为引用传入的持续时间对象的指针,并将范围的持续时间添加到此。#include#includestructtimer{usingclock=std::chrono::high_resolution_clock;usingtime_point=clock::time_point;usingduration=clock::duration;duration*d_;time_pointstart_;timer(durat

c++ - 涉及通用引用的过载解决方案

对于下面的代码:classA{};templatevoidf(T&a){}templatevoidf(T&&a){}intmain(){Aa;f(a);}clang++将调用绑定(bind)到第一个重载,而g++报告不明确的调用。哪一个采取了正确的行动? 最佳答案 gcc4.9.020140302和clang3.5(trunk202594)都正确地选择了第一个版本。作为hvd好心给了我thereferencesincomments:这是一个微妙的问题,有adefectreport,4.9之前的gcc实现实现了早期的缺陷,参见Temp

c++ - CMake 和 Clang 工具链接错误(树外)

我正在尝试编译RecursiveASTVisitorexampleofClang使用CMake文件。构建项目进行得很顺利,但是,由于对LLVM和Clang库的多个undefinedreference,链接C++可执行文件失败。我正在LLVM/Clang源文件树之外构建示例。这是我的CMakeLists.txt(我正在使用FindClang.cmakeandFindLLVM.cmakefromthisproject):cmake_minimum_required(VERSION2.8.4)project(ifcount)set(CMAKE_MODULE_PATH${CMAKE_CURRE

C++14:从参数值初始化 constexpr 变量

假设我有一个类可以通过constexpr函数返回常量表达式:templatestructFoo{constexprintBar()const{returnN;}};如果我想从Foo::Bar()初始化constexpr值,我应该如何传递类型为Foo的参数?我已经尝试了这两个,每个示例中都有一个constexpr变量来测试它是否可以被初始化:templateconstexprintByValue(Foof){constexprinti=f.Bar();returnf.Bar();}templateconstexprintByReference(constFoo&f){constexpri

c++ - VS2015 和 clang 编译此代码,但 g++ 拒绝它。哪一个是正确的?

VS2015和clang编译这段代码,但是g++rejectsit.namespaceA{structB{friendvoidf();};}voidA::f(){}intmain(){}我认为g++是正确的,因为7.3.1.2/3中的注释:Ifafrienddeclarationinanon-localclassfirstdeclaresaclass,function,classtemplateorfunctiontemplate97thefriendisamemberoftheinnermostenclosingnamespace.Thefrienddeclarationdoesno

c++ - 使用 c++1z 在 <functional> 上出现 clang 4 构建错误

我刚刚将我的archlinux系统更新到最新版本,其中包括gcc7.1.1。尝试构建这个:#includeintmain(intargc,char**argv){return1;}使用命令clang++main.cpp-std=c++1z导致错误:Infileincludedfrommain.cpp:1:Infileincludedfrom/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/7.1.1/../../../../include/c++/7.1.1/functional:60:Infileincludedfrom/usr/bin/../lib

c++ - `constexpr` 变量 "used in its own initializer": Clang vs. GCC

这个问题似乎与anexistingone有关,但我不明白theanswerthere中提供的“可移植解决方法”(涉及constautothis_=this;)而且我认为下面的例子更容易理解。我正在使用以下C++17代码片段(livedemo):#includestructTest{constchar*name_{nullptr};constTest*src_{nullptr};constexprTest(constchar*name)noexcept:name_{name}{}constexprTest(constTest&src)noexcept:src_{&src}{name_=s

c++ - "uses of target_link_libraries must be either all-keyword or all-plain"

我设法构建了llvm和clang,现在我正在尝试根据clangdocs创建一个ClangTool.但是当我尝试构建它时出现以下错误:CMakeErrorattools/clang/tools/loop-convert/CMakeLists.txt:6(target_link_libraries):Thekeywordsignaturefortarget_link_librarieshasalreadybeenusedwiththetarget"loop-convert".Allusesoftarget_link_librarieswithatargetmustbeeitherall-k

c++ - 执行限定名称查找时 Clang 和 GCC 之间的不同行为

考虑以下程序:#includenamespaceN{intj=1;}namespaceM{typedefintN;voidf(){std::cout用clang编译它会出现以下编译器错误:prog.cc:10:22:error:'N'(aka'int')isnotaclass,namespace,orenumerationstd::coutGCC不会给出任何编译器错误。我想弄清楚我应该为哪个编译器提交错误报告。哪个编译器具有正确的行为以及原因(对c++标准的引用)?Wandbox-Clang:http://melpon.org/wandbox/permlink/s0hKOxCFPgq5

c++ - clang 的 `-Ofast` 选项在实际中有什么作用,特别是对于与 gcc 的任何差异?

类似于的SO问题Whatdoesgcc'sffast-mathactuallydo?并且与Clangoptimizationlevels的SO问题相关,我想知道什么clang的-Ofast优化在实际方面的作用,这些是否与gcc完全不同,或者这是否比编译器更依赖于硬件。根据clang优化级别的公认答案,-Ofast添加到-O3优化:-fno-signed-zeros-freciprocal-math-ffp-contract=fast-menable-unsafe-fp-math-menable-no-nans-menable-no-infs.这似乎完全与float学相关。但是这些优化对