草庐IT

c++ - CMake "clang++ is not able compile a simple test program"(软呢帽 20)

所以我尝试安装clang+cmake来编译一个简单的C++程序,但出现以下错误:--TheCcompileridentificationisGNU4.8.3--TheCXXcompileridentificationisClang3.5.0--CheckforworkingCcompiler:/usr/bin/cc--CheckforworkingCcompiler:/usr/bin/cc--works--DetectingCcompilerABIinfo--DetectingCcompilerABIinfo-done--CheckforworkingCXXcompiler:/usr/

c++ - 模板类实例化的多重继承以及对成员函数的访问

让我们看一下代码:templateclassS{public:voidadd(Cc){++cnt;}size_tsize()const{returncnt;}private:size_tcnt{};};structFoo1{};structFoo2{};structFoo3{};classZ:publicS,publicS,publicS{public:usingS::add;usingS::add;usingS::add;usingS::size;//(1)usingS::size;//(2)usingS::size;//(3)};用法是这样的:Zz;z.add(Foo1{});z.

c++ - Clang UBSAN 报告类型 'std::_Ios_Fmtflags' 的无效值

以下代码用clangUBSAN编译会崩溃#include#include#include#includetemplateinlinestd::stringfloatToString(Ti){printf("infloatToString\n");std::stringstreamss;ss.precision(6);ss用Clang3.6编译:$>clang++-3.6-fsanitize=undefined-fno-sanitize=float-divide-by-zero,vptr,function-fno-sanitize-recover-otesttest.cpp然后程序崩溃了

c++ - 如何将 override 关键字添加到大型 C++ 代码库?

我有一个包含数千个源文件的大型C++代码库。我想在适当的地方添加override关键字。我的一些明显被覆盖的函数实际上并没有覆盖基类中的任何函数,我想捕获这些或至少让它们脱颖而出。我尝试手动执行,但代码库太大。我尝试使用clang-modernize,但它没有提供有用的说明。我还担心它无法理解为VisualStudio编写的代码库。如何在不花费人工周或更多时间的情况下将override关键字添加到我的代码库中? 最佳答案 似乎clang-modernize已经进入了clang-tidy这支持这一点。示例代码(test.cpp):st

c++ - clang 和 gcc 在处理模板生成和静态 constexpr 成员时的不同行为?

考虑以下程序(抱歉太长了;这是我能想到的表达问题的最短方式):#include#include#includeusingnamespacestd;std::vector&test_vector(){staticstd::vectorrv;returnrv;}templateclassRegistrarWrapper;templateclassRegistrar{Registrar(){auto&test_vect=test_vector();test_vect.push_back(std::type_index(typeid(T)));}friendclassRegistrarWrap

c++ - 什么是 clang-check 的垃圾值

我收到以下警告:test.cpp:14:25:warning:Therightoperandof'/'isagarbagevaluereturn(std::abs(a)/size)>10;^~~~~对于这段代码:#include#include#include#includeusingnamespacestd;doublepitchDetect(conststd::vector>&dft,unsignedintsamplingRate)noexcept{if(dft.empty())return0.0;autoit=find_if(begin(dft),end(dft),[size=d

c++ - 使用 clang 对 std::atomic 函数的调用不明确

我正在尝试使用clang编译我的代码,我之前使用的是g++。我在编译以下代码时遇到错误:#includetypedefvoid(*my_func)();intmain(intargc,char**argv){std::atomic_func;_func();return0;}错误是:a.cpp:23:3:error:calltoobjectoftype'std::atomic'isambiguous_func();^~~~~/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/atomic:304:7:

c++ - 变量 args SFINAE 默认构造函数在 clang 中工作,但在 Visual Studio 2015 中失败

任何人都知道这段代码是否不好,或者VS是否有错误,或者Clang是否允许?我认为我的构造函数不应该接受任何参数并通过enable_if检查-但VS在某处说“不”。VisualStudio2015Update2出现以下错误:source_file.cpp(##):errorC2512:'Foo::Foo':noappropriatedefaultconstructoravailable现场直播:http://rextester.com/VWAI2954VS存在错误:http://rextester.com/PTDSS2853#include#includeusingnamespacest

c++ - 在 OSX 10.11.4 + clang 上抛出异常导致 SIGSEGV

给定以下代码:#include#includeusingnamespacestd;classexception_base:publicruntime_error{public:exception_base():runtime_error(string()){}};classmy_exception:publicexception_base{public:};intmain(){throwmy_exception();}这在GNU/Linux和Windows上运行良好,并且在最新更新到版本10.11.4之前在OSX上运行良好。我的意思是,因为没有捕获到异常,所以调用了std::termi

c++ - 如何使用 clang 和选项 -std=c++11 编译项目,使用 autotools

我正在使用C和C++代码开发软件。我最近在c++11标准中添加了一些代码。在configure.ac我写道:forfin'-std=c++11''-std=c++11-stdlib=libc++'doAX_CHECK_COMPILE_FLAG([$f],[CXXFLAGS="$CXXFLAGS$f"stdpass=true],[],[],[])${stdpass-false}&&breakdoneif!"${stdpass-false}";thenAC_MSG_ERROR([UnabletoturnonC++11modewiththiscompiler])fi使用gcc我没问题,一切顺