草庐IT

c++ - 这个使用 <locale> 的简单 C++ 程序是否正确?

此代码似乎在(ubuntu可信)版本的gcc和clang中以及通过mingw在VM上的Win7中工作正常......最近我升级到Wily并且使用clang构建的构建在这里始终崩溃。#include#include#includeintmain(){std::cout有时它是一个乱码字符串,后跟Aborted:Coredumped有时是invalidfree.$./a.outThelocaleis'en_US.UTF-8QX�у�X�у����0�����P�����\�(��\�(��\�(��h��t�������������y���������ț�ԛ�������en_US.UTF

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++ - SIGFPE 访问 unordered_map 时

我有一个unordered_map其中Block是一个简单的结构,定义如下:structBlock{size_tstart;size_tend;booloperator==(constBlock&b)const{returnstart==b.start&&end==b.end;}};namespacestd{templatestructhash{size_toperator()(constBlock&b)const{returnb.start;}};}当尝试访问map时,我确实在gdb中收到以下错误消息(g++4.7.1和clang++3.1都相同):Programreceivedsi

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