草庐IT

c++ - 使用 clang 从 stdin 自动完成

我已经在Emacs中设置了自动完成环境,使用clang2.8作为解析器。它运行良好,但依赖于在完成之前将当前编辑的缓冲区保存到文件中。这很慢,所以我试图让clang解析通过stdin提供给它的文件,但到目前为止运气不好。我在解析文件时输入clang的命令行如下:clang-cc1-fsyntax-only-Iinclude/-code-completion-atfoo.cpp:10:20foo.cpp这很好用。但是尝试从stdin读取失败。我试过这个:catfoo.cpp|clang-xc++-cc1-fsyntax-only-Iinclude/-code-completion-at-

c++ - Clang 前端 API 的所有权问题

我正在使用ClangC++API。由于API没有正确使用智能指针,我一直在努力解决所有权问题。到目前为止,我自己解决了所有发现的问题,但这个问题让我很烦恼。当代码执行时,我遇到了访问冲突。我相当确定这是一个双重删除,但由于文档不存在,我不知道去哪里看。幸运的是,复制程序相当短。有什么建议吗?#define_SCL_SECURE_NO_WARNINGS#pragmawarning(push,0)#include#include#include#include#include#include#include#include#include#include#include#include#i

c++ - 我如何针对在 xcode/clang/macos 中使用 libc++ 编译的静态库编译应用程序?

当我尝试编译一个测试控制台应用程序以测试同一工作区中静态库的某些功能时,我在二进制文件的链接阶段遇到了问题,只有当我选择使用libc++标准库时才会发生。缺少符号错误如下:Undefinedsymbolsforarchitecturex86_64:"std::__1::basic_string,std::__1::allocator>::empty()const",referencedfrom:libtorrent::torrent::replace_trackers(std::__1::vector>const&)inlibLibOFFTorrent-xcode.a(torrent.

c++ - clang 不编译我的代码,但 g++ 可以

谁能帮我处理这段代码:#include#includestructnonsense{};templatetypenamestd::enable_if::value,int>::typefo(void*const){return0;}templatetypenamestd::enable_if::value,int>::typefo(void*const){return1;}typedefint(*func_type)(void*);templatevoidrun_me(){staticstructnonsensedata;typedefstd::pairpair_type;std::v

c++ - Clang 自动变量模板错误

我去看看你是否可以在变量模板声明中使用auto。templateautoF=T{};很好,但是一旦您尝试使用它,就会发出咔哒声。intf=F;//error:cannotinitializeavariableoftype'int'withanlvalueoftype'auto'autof=F;//Stacktracedecltype(F)f=F;//StackFacestd::cout)>::value;//falsestd::cout)).name();//Stacktracestd::cout),decltype(F)>::value;//truedecltype(auto)、au

c++ - 在模板参数的方法中添加类型转换时出现 clang 错误

我有一个模板结构,它将方法的类型和指向方法的指针作为参数,并将其包装在类似C的函数中:templatestructproxy;templatestructproxy{staticRcall(T&obj,Args&&...args){return(obj.*mf)(std::forward(args)...);}};proxy结构在简单的场景中按预期工作,例如:structFoo{intfoo(intx){returnx+1;}};...Foof;proxy::call(f,10);问题是当我在可能展开到的宏中使用代理时:proxy::call(f,10);在clang中,错误是:err

c++ - 最小程序在 g++ 上产生 Valgrind 警告,但在 clang 或 VS 上不产生警告

我一直在疯狂地追踪一个中型项目中的内存错误。我将一个代码最小化为以下代码,并验证这会导致Valgrind在注释行号处发出无效读取警告。我正在为项目使用g++4.8.2(Debian4.8.2-16),使用-std=c++11-O0进行编译。g++4.7.0也会产生错误,4.4.6在稍作修改的版本(删除C++11)上也会产生错误。clang++不会导致错误,VS2013也不会。我的问题是:我是否在不知不觉中从事未定义的行为?这是Valgrind误报吗?如果是,我如何才能让自己放心,以后会遇到这样的情况?这段代码相当脆弱——特别是,让foo通过引用获取坐标可以消除这个问题,为Coord选择

c++ - 对于 CLang 中的 enable_if 错误(错误 11723)是否有更好的解决方法?

理想情况下,我们可以使用enable_if做类似的事情:#includenamespacedetail{enumclassenabler_t{DUMMY};}templateusingenable_if_u=typenamestd::enable_if::type;templateusingdisable_if_u=typenamestd::enable_if::type;template::value>...>inta(){return0;}template::value>...>doublea(){return0.0;}intmain(){autox=a();}恕我直言,这是最好的

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++ - 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然后程序崩溃了