草庐IT

incremental-compiler

全部标签

c++ - 分配给右值 : why does this compile?

在下面的例子中:classA{private:doublecontent;public:A():content(0){}Aoperator+(constA&other){content+=other.content;return*this;}voidoperator=(constA&other){content=other.content;}};A是double的简单包装器,+和=运算符已被重载。在以下使用中:intmain(intargc,char*argv[]){Aa,b,c;(a+b)=c;//Whyisthisoperationlegal?}为什么(a+b)=c可以编译?我想知

C++ 模板 : How to put nontype constraints in compiling time

假设我有以下模板templateclassFOO{....}事实上,我要求(I>=F)。如果有人误用FOOa;我希望提出一个编译错误。如何做到这一点?谢谢 最佳答案 一种方法可能是C++11的static_assert,它类似于assert,但在编译时检查:templateclassFOO{static_assert(I>=F,"IneedstobelargerorequaltoF");...}; 关于C++模板:Howtoputnontypeconstraintsincompiling

c++ - 警告 LNK4075 : ignoring '/EDITANDCONTINUE' due to '/INCREMENTAL:NO' specification

我有一个链接到外部.lib(libprotobuf.lib)的项目。当我在发行版中编译时,没有警告。但是,当我在调试中编译时,我收到此警告:warningLNK4075:ignoring'/EDITANDCONTINUE'dueto'/INCREMENTAL:NO'specificationFile:\libprotobuf.lib(message_lite.obj)我一直在研究这个问题,从thisquestion.开始我一直在调整项目的选项,并且(在调试配置中):/Zi-所以编辑并继续不应该打开。/INCREMENTAL-所以增量应该打开。知道为什么我仍然收到此警告吗?我最好的猜测是

Python 扩展 : using different compiler flags for a C parts and C++ parts

对于我的python扩展,我有C(来自嵌入式库)和C++文件,它们被编译并链接在一起。只有C++部分与Python接口(interface)(通过SWIG)。这在VS2015的windows和linux下的gcc中都有效。但是,对于gcc,C++文件需要一组不同于C文件的编译器标志(例如-std=c++11、-Wno-reorder),以避免出现有关C中不正确标志的警告。在setuptools/distutils中有没有办法单独更改每个文件的编译器标志,例如。基于文件扩展名?我已经使用了来自https://stackoverflow.com/a/36293331/3032680的自定义

c++ - g++ : Is there a way to access compile flags inside the code that is being compiled?

有没有一种方法(例如,定义的常量)来访问正在编译的代码中运行编译器的编译标志。例如,我想要一个程序来写入编译时使用的标志。intmain(){std::coutgcc/g++是否存在这样的常量?或者更好:是否有在gcc和clang中都定义的常量?我对检查优化级别和-march标志的值特别感兴趣。那么,如果没有显示所有标志的常量,是否至少有显示这些值的常量? 最佳答案 以下命令打印出所有预定义的宏:g++-dM-E-这适用于gcc和g++。您可以自行检查-不幸的是,没有宏可让您轻松访问完整的gcc/g++命令行。幸运的是,大多数-m.

C++ fatal error C1001 : An internal error has occurred in the compiler

在Release模式下编译时出现以下错误。1>d:\users\eyal\projects\code\yalla\core\src\runbox\win32\window.cpp:fatalerrorC1001:Aninternalerrorhasoccurredinthecompiler.1>(compilerfile'f:\dd\vctools\compiler\utc\src\p2\main.c',line249)1>Toworkaroundthisproblem,trysimplifyingorchangingtheprogramnearthelocationslistedab

c++ - CMake 识别 MSVC(C 和 CXX),但仍然抛出 'No CMAKE_*_COMPILER found'

我一直在四处寻找,这个问题似乎以各种形式出现了很多。最常见的原因是缺少编译器,即C和CXX编译器未知。然而,就我而言,情况并非如此。我的机器上有C和C++编译器,例如通过VisualStudio,一切都可以正常编译。但是,通过cmake,会发生这种情况:>cmake.输出:--Buildingfor:VisualStudio142015--TheCcompileridentificationisMSVC19.0.24215.1--TheCXXcompileridentificationisMSVC19.0.24215.1CMakeErroratCMakeLists.txt:12(pro

c++ - 具有模板特化的 constexpr 数组成员 : inconsistent behavior cross compilers

考虑以下代码:#includetemplatestructfoo{};templatestructfoo{staticconstexprcharvalue[]="abcde";};templatestructbar{staticconstexprcharvalue[]="abcde";};templatestructbaz{staticconstexprintvalue=12345;};intmain(){charc=foo::value[2];chard=bar::value[2];inte=baz::value;std::cout编译时:clang++-std=c++14./tes

c++ - 与 friend 一起上课而不是前向声明,: which compiler is correct

这个问题在这里已经有了答案:Friendmethod"notdeclaredinthisscope"inC++(1个回答)Error:'FriendMemberFunctionName'wasnotdeclaredinthisscope(3个答案)关闭3年前。我有这个简单的C++程序:#includestructobj{friendintf(int);voidm(intx){std::cout如果我使用GNUC++编译器g++进行编译,我会得到错误prog.cpp:7:55:error:'f'wasnotdeclaredinthisscope但是,如果我使用cl(和/W4)编译它,它会

c++ - SFINAE : Detecting if a function is called by a compile time known value

我喜欢在我的一个ctors以编译时已知值被调用时做一些检查。有办法检测吗?所以当有人调用它时:Aa(10);因为10是编译时已知常量,所以我喜欢调用一个特殊的构造函数,如下所示:template>A(intValue){}知道如何解决这个问题吗?谢谢! 最佳答案 积分常量可以解决您的问题:structA{template*=nullptr>A(std::integral_constant){}};然后,你可以像这样使用它:Aa{std:integral_constant{}};为了便于使用,您还可以使用类似于boost::hana的