草庐IT

compiler-bug

全部标签

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++ - 使用声明和访问修饰符的嵌套类

在编译一些代码时,我遇到了一个编译器错误,这个错误对我来说很奇怪,并且与继承、嵌套类、使用声明和访问修饰符有关。基本上,派生类型的目的是公开基类型的嵌套protected类。以下简短示例演示了该问题:classBase{protected:structNested{enumvalue_enum{val=0,val2,val3};};};classDerived:publicBase{public:usingBase::Nested;};intmain(intargc,char**argv){//Base::Nestedaa;//error,as(I)expected//Base::Ne

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++ - 有状态 lambda 问题 - Microsoft 编译器版本 19.16.27024.1

您好,我对有状态的lambda表达式有疑问。这是一个虚拟示例,但在我看来,ms编译器做错了什么,或者我有一些未定义的行为?代码:intmain(){autostart=[x=1,z=1]()mutable{gotoresume;for(;;++z){for(x=1;x3)return1;}}};start();}微软编译器版本19.16.27024.1cl-O2/std:c++17(or-O1,-Ox)----->打印'1'然后无限数量的'2'(我认为是错误的)cl-Od/std:c++17----->打印12334g++(Ubuntu7.3.0-27ubuntu1~18.04)7.3

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的

c++ - C1001 : An internal error has occurred in the compiler

这应该是不言自明的。我正在尝试实现分布排序,但MSVC编译器崩溃了。这似乎是用我的SFINAE检测成员函数的特定情况,如果我不将indexert传递给函数,或者替换has_get_index,这似乎不会发生。如果我删除剩余的索引器重载中的任何一个,它也不会发生。如果sortable有一个getIndex()const成员,问题仍然存在。1>test.cpp(34):fatalerrorC1001:Aninternalerrorhasoccurredinthecompiler.1>(compilerfile'msc1.cpp',line1420)1>Toworkaroundthispro

c++ - 这是(枚举 : char {}) a gcc bug?

在gcc-4.5下打印0,在gcc-4.6下打印1。#includeenumVenueId:char{};intmain(intargc,char**argv){VenueIdv=(VenueId)'P';std::cout 最佳答案 根据标准,VenuedId具有char类型作为基础类型,因此v应包含char'P',v=='P'应该产生true。§7.2枚举声明Eachenumerationdefinesatypethatisdifferentfromallothertypes.Eachenumerationalsohasanun