草庐IT

static_warning

全部标签

c++ - `static constexpr auto` 使用未命名枚举初始化的数据成员

我正在开发一个C++11项目,仅使用clang++-3.4,并决定使用g++-4.8.2进行编译以防产生的错误有任何差异。原来g++拒绝了clang++接受的一些代码。我已将问题简化为下面给出的MWE。enum{a};templatestructfoo{staticconstexprautovalue=a;};intmain(){staticconstexprautor=foo::value;}foo.cpp:5:23:error:‘constfoo::value’,declaredusinganonymoustype,isusedbutneverdefined[-fpermissiv

c++ - 我什么时候在 C++ 中使用 const volatile、register volatile、static volatile?

我想知道volatile关键字与register、const和static结合的不同用途关键词。我不确定有什么影响,所以我认为:registervolatileintT=10;建议编译器将T存储在寄存器中,T的值可以从外部某处(操作系统、硬件、另一个线程)修改constvolatileintT=10;程序本身不能修改T,但是T可以在代码之外的地方修改。staticvolatileintT=10;如果T是类的数据成员,则意味着该类的所有对象都具有相同的T值,并且T可以从外部某处修改。如果T是文件中的全局变量,则其他文件(属于项目的一部分)中的源代码无法访问T,但可以从外部某处访问T。如果

c++ - 我在哪里将常量字符串放在 C++ : static class members or anonymous namespaces? 中

我需要定义一些仅由一个类使用的常量字符串。看起来我有三个选择:将字符串直接嵌入到使用它们的位置。将它们定义为类的私有(private)静态常量成员://A.hclassA{private:staticconststd::stringf1;staticconststd::stringf2;staticconststd::stringf3;};//A.cppconststd::stringf1="filename1";conststd::stringf2="filename2";conststd::stringf3="filename3";//stringsareusedinthisfil

c++ - "use -D_SCL_SECURE_NO_WARNINGS"是什么意思?

我在尝试编译曲线压缩程序时出错,错误号C4996,带参数的函数调用可能不安全。它告诉我使用上述内容。错误来自xutility头文件,我以前从未见过它。这是我必须输入控制台的标志吗?网上几乎没有提到它... 最佳答案 -D是一个命令行编译器标志,它使其余文本被视为代码中存在#define。在解决方案资源管理器中,右键单击项目,选择“属性”。项目属性页面将打开。展开左侧树中的“>C/C++”条目并在其下选择“预处理器”。右Pane中的顶部条目应该是“预处理器定义”。在该编辑框中,添加_SCL_SECURE_NO_WARNINGS,用;将

c++ - How to get around GCC ‘*((void*)& b +4)’ may be used uninitialized in this function warning while using boost::optional

我有类似下面的代码:#include::boost::optionalgetitem();intgo(intnr){boost::optionala=getitem();boost::optionalb;if(nr>0)b=nr;if(a!=b)return1;return0;}当使用GCC4.7.2和Boost1.53进行编译时,使用以下命令:g++-c-O2-Wall-DNDEBUG发出以下警告:13:3:warning:‘((void)&b+4)’maybeuseduninitializedinthisfunction[-Wmaybe-uninitialized]显然,根本问题在

c++ - OS X Yosemite 中的 gcc 4.9.1 - gcc : warning: couldn’t understand kern. osversion ‘14.0.0'

我安装了OSXYosemite,现在我遇到了gcc4.9.1编译器的大问题。我希望有人可以帮助我。我尝试编译我的程序并收到警告消息:gcc:warning:couldn’tunderstandkern.osversion‘14.0.0'我在谷歌上搜索并找到https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61407我尝试应用补丁做:sudopatch-p1在gcc文件夹中:/usr/local/bin/gcc我收到了消息:can'tfindfiletopatchatinputline5Perhapsyouusedthewrong-por--str

c++ - static_cast<T>(-1) 是在没有 numeric_limits 的情况下生成全一位数据的正确方法吗?

我在一个无法访问C++标准库的环境中编写C++代码,特别是无法访问std::numeric_limits.假设我要实现templateconstexprTall_ones(/*...*/)专注于无符号整数类型,我该放什么?具体来说,是static_cast(-1)够好了?(根据我猜的大小,我可以将其他类型视为无符号字符数组。) 最佳答案 使用bitwiseNOT接线员~在0.TallOnes=~(T)0;一个static_cast(-1)假定二进制补码,这是不可移植的。如果您只关心无符号类型,hvd'sanswer是要走的路。工作示

c++ - initializer_list::size() 上的 static_assert

为什么是std::initializer_list::size不允许在static_assert中使用,即使它被声明为constexpr在我的libstdc++(v.4.6)中?例如下面的代码:templateclassPoint{public:Point(std::initializer_listinit){static_assert(init.size()==Length,"Wrongnumberofdimensions");}};intmain(){Pointq({1,2,3});return0;}给出以下错误:test.C:Inconstructor‘Point::Point(

c++ - 警告 C4800 : 'int' : forcing value to bool 'true' or 'false' (performance warning)

我的代码中有这个问题:boolCBase::isNumber(){return(id&MID_NUMBER);}boolCBase::isVar(){return(id&MID_VARIABLE);}boolCBase::isSymbol(){return(id&MID_SYMBOL);} 最佳答案 仅供引用:强制转换不会隐藏警告bydesign.类似return(id&MID_NUMBER)!=0;应该明确说明“我要检查这个值是否为零”并让编译器高兴 关于c++-警告C4800:'in

c++ - 警告 : ISO C++ forbids converting a string constant to ‘char*’ for a static `constexpr char*` data member

这个问题在这里已经有了答案:constexprconstvsconstexprvariables?(3个回答)关闭3年前。为什么这段代码会返回警告warning:ISOC++forbidsconvertingastringconstantto‘char*’[-Wwrite-strings]如果Aconstexprspecifierusedinanobjectdeclarationornon-staticmemberfunction(untilC++14)impliesconst.Aconstexprspecifierusedinafunctionorstaticmembervariab