草庐IT

clang-extensions

全部标签

C++ 函数到指针的隐式转换 : which compiler is right? Clang 和 GCC 不同意

templatestructA{};voidfunc();Aa;//sameresultwithAa;此代码使用Clang(包括最新的8.0.0)编译,但不能使用GCC(包括最新的9.1)编译。GCC说:错误:'void()'不是模板非类型参数的有效类型哪个编译器是正确的,为什么?更新我猜GCC是错误的,因为以下代码在Clang和GCC上都可以编译:templatestructA{};voidfunc();Aa;//sameresultwithAa;因此与GCC在第一个示例中的报告相反,void()似乎是“模板非类型参数的有效类型” 最佳答案

c++ - g++ 和 clang++ 自动参数模板特化的不同行为

使用C++17auto模板参数我遇到了另一个g++/clang++分歧。给定以下简单代码templatestructfoo;templatestructfoo{};intmain(){foof42;//我看到clang++(8.0.0,例如)编译g++(9.2.0,例如)给出以下错误的代码prog.cc:Infunction'intmain()':prog.cc:12:13:error:aggregate'foof42'hasincompletetypeandcannotbedefined12|foof42;|^~~如果我们使用int常量而不是long常量,两个编译器都会编译foof4

c++ - 强枚举 typedef : clang bug or c++11 standard uncertainty?

对于这样的代码:typedefenumFooEnum:intFooEnum;enumFooEnum:int{A=1,B};clang(linux/7.0.0)报告没有错误[-c-std=c++11-pedantic],但是gcc(linux/8.2.1)不编译它:g++-c-std=c++11-pedantictest2.cpptest2.cpp:1:28:error:expected';'or'{'before'FooEnum'typedefenumFooEnum:intFooEnum;^~~~~~~test2.cpp:1:28:error:expectedclass-keybefo

c++ - "template"不需要关键字? [gcc/clang/Comeau 错误?]

这是测试代码templatevoidf(){Tt;t.f(0);//compilesevenwithoutthe"template"keyword,whatamImissing?}classabc{public:templatevoidf(int){}};intmain(){f();}我正在使用g++4.4.6。谢谢P.S:我已经大大编辑了我的问题。请不要介意。编辑:我向EDG的人问了这个问题,这是MikeHerrick不得不说的Wedodiagnosethisasanerrorin--strictmodeaswellasanymodethatenablesdependentnamel

c++ - 是否有一个开关可以用 clang 禁用三字母?

我有一些(遗留)代码是我第一次使用clang构建的。代码是这样的:sprintf(buf,"%s",p1,p2);Clang给出以下警告(-Werror错误):test.c:6:33:error:trigraphconvertedto'}'character[-Werror,-Wtrigraphs]sprintf(buf,"%s",p1,p2);^显然??>不是三字母组,所以我想完全禁用三字母组(源代码没有故意在任何地方使用它们)。我已经尝试过-no-trigraphs但这不是一个真正的选择:clang:warning:argumentunusedduringcompilation:'

c++ - G++、clang++ 和 std::function

我只是在玩弄来自C++11的新std::function,我写了一个使用clang++3.2和英特尔C++编译器13.1编译但不使用g++4.8编译的示例。在我将其报告为错误之前,我想我应该检查一下我没有做一些非常愚蠢的事情,并且这实际上应该可以编译。那么,以下代码是否适用于c++11?templatevoidmap(C&c,std::functionf){for(auto&x:c){x=f(x);}}intmain(){std::vectorv;v.push_back(1);v.push_back(2);v.push_back(3);map(v,[](intx){returnx+2;

c++ - clang:强制循环展开特定循环

有没有办法告诉clang展开特定循环?谷歌搜索答案给我的命令行选项会影响整个编译器,而不是单个循环。GCC也有类似的问题---Tellgcctospecificallyunrollaloop---但那里提供的答案不适用于clang。那里建议的选项1:#pragmaGCCoptimize("unroll-loops")似乎被默默地忽略了。事实上#pragmaGCCakjhdfkjahsdkjfhskdfhd也被默默地忽略了。选项2:__attribute__((optimize("unroll-loops")))导致警告:warning:unknownattribute'optimize

c++ - 如何使用 windows/cygwin 从 CMakeLists.txt 中的 Clion 中的 GCC 和 Clang 之间切换

我放set(CMAKE_CXX_COMPILER"/usr/bin/clang.exe")运行/清理,运行/构建。我收到如下链接错误:undefinedreferenceto`std::ios_base::Init::~Init()':undefinedreferenceto`__gxx_personality_v0'大概还有其他变量需要改变。尝试将-lstdc++添加到CMAKE_CXX_FLAGS,但没有什么不同。例如,是否有CLion方式而不是CMake方式?谢谢。 最佳答案 使用CMake指定编译器有点微妙。尽管您使用的方法

c++ - 如何用 clang 构建 clang?

我已经成功地使用MSVC和MinGW构建了clang(3.2)。但我认为这不是“纯粹”的clang。那么有人可以给我一些关于如何使用clang构建clang(Windows/Linux)的说明或Material吗?我们可以独立使用clang(不依赖于GCC或MSVC)。谢谢大家! 最佳答案 我们会得到一个旧版本的clang,比如3.1。(您几乎可以安装为您的操作系统预编译的任何版本)获取更新版本(如3.2)的源代码。然后(我喜欢cmake+ninja(http://clang.llvm.org/docs/HowToSetupTool

c++ - 为什么这段代码在 Clang++ 中有效,但在 G++ 中无效?

考虑以下代码:structFoo{intx,y;Foo()=default;Foo(constFoo&)=delete;Foo&operator=(constFoo&)=delete;};intmain(){Foof1{1,2};Foof2={1,2};}使用clang++编译不会产生错误:$clang++--versionAppleLLVMversion4.2(clang-425.0.28)(basedonLLVM3.2svn)Target:x86_64-apple-darwin12.4.0Threadmodel:posix$clang++-std=c++11-stdlib=libc