草庐IT

clang_complete

全部标签

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但是这些标志都不起作

c++ - Clang VS VC++ :"error: declaration of ' T'阴影模板参数”

我正在尝试为theclassiccopy&swapidiom编译以下代码在我的Mac上使用clang3.3templateclassnode{private:node*left;node*right;Tvalue;public:friendvoidswap(node&,node&);//otherstuff}然而链接器却报错了。我现在明白我应该将函数声明为模板。但是,如果我按照建议的样式进行操作,则会发生错误here来自MSDN:templateclassArray{T*array;intsize;public:template//...templatefriendArray*comb

c++ - Clang 无法再使用 <functional> header 编译程序

我在运行ArchLinux的系统上使用clang版本4.0.0,它一直运行良好,但最近我无法再编译使用某些STLheader的程序了!详细信息:clang--version的输出:clangversion4.0.0(tags/RELEASE_400/final)Target:x86_64-unknown-linux-gnuThreadmodel:posixInstalledDir:/usr/bingcc--version的输出:gcc(GCC)7.1.120170528示例:我尝试编译以下简单程序:#includeintmain(){return0;}我正在使用以下命令:clang++

c++ - 模板模板参数在 Clang 但不是 GCC 下导致编译器错误

这个问题在这里已经有了答案:Templatetemplateparameteranddefaultvalues[duplicate](1个回答)关闭4年前。同时帮助解决toomanytemplateparametersintemplatetemplateargument中提到的问题我脑子里出现了一个问题:在这种情况下,哪个编译器是正确的编译:templateclassOp>classFunction{};template::value||std::is_floating_point::value>structOperator;templatestructOperator{};templ