草庐IT

gcc-statement-expression

全部标签

c++ - GCC 4.4/4.5 unique_ptr 不适用于 unordered_set/unordered_map

有什么地方可以确认吗?我不确定是GCC的问题还是我的代码的问题。例如,以下代码无法编译:#include#includeusingnamespacestd;intmain(){unordered_set>s;unique_ptrp(newint(0));s.insert(move(p));return0;}错误信息太大,我不想放在这里。GCC版本为4.5.3,编译标志为-std=gnu++0x。也在4.4.5上测试过。 最佳答案 GCC4.6.1按原样接受您的代码,我认为它没有任何问题(即关联容器的value_type必须是Empl

c++ - 将 gcc 属性与 C++11 属性语法一起使用

我正在尝试使用GCCattributes与C++11syntax.例如这样的事情:staticvoid[[used]]foo(void){//...}但我得到以下信息:warning:‘used’attributeignored[-Wattributes]staticvoid[[used]]foo(void)^为什么该属性被忽略?是否可以将GCC属性用作C++属性? 最佳答案 [[gnu::used]]staticvoidfoo(void){}首先,属性只能出现在特定的地方,否则你会得到:x.cc:1:13:warning:attr

c++ - 如何使 `short-circuit evaluation` 在 `fold expressions` 中也可用?

#include#defineFORWARD(arg)\std::forward(arg)templateconstexprboolAndL(Args&&...args){return(...&&FORWARD(args));}templateconstexprboolAndR(Args&&...args){return(FORWARD(args)&&...);}intmain(){bool*pb=nullptr;false&&(*pb=true);//okatruntime.AndL(false,(*pb=true));//erroratruntime!AndR(false,(*pb

c++ - 如何为忘记的返回语句打开 gcc 警告?

如何为忘记的返回语句打开gcc警告?它应该在以下情况下警告我:intfoo(){std::cout我知道-Wall会打开该警告,但它会启用太多其他警告。 最佳答案 根据gcc的onlinedocumentation,-Wall打开:-Waddress-Warray-bounds(onlywith-O2)-Wc++0x-compat-Wchar-subscripts-Wenum-compare(inC/Objc;thisisonbydefaultinC++)-Wimplicit-int(CandObjective-Conly)-Wim

c++ - 使用 GCC 和 C++11 实现类型 "long double"

我尝试搜索有关longdouble的信息,到目前为止,我了解到编译器对它的实现有所不同。在Ubuntu(XUbuntu)Linux12.10上使用GCC时,我得到了这个:doublePId=acos(-1);longdoublePIl=acos(-1);std::cout.precision(100);std::cout输出:PId8:3.141592653589793115997963468544185161590576171875PIl16:3.141592653589793115997963468544185161590576171875有人明白为什么他们输出(几乎)相同的东西吗

c++ - 此模板代码中的错误 "Expected Expression"

为什么会出现此错误,我该如何解决?templatestructfoo{templatevoidhello(){}};templatestructbar{voidworld(){foof;f.hello();//Error:Expectedexpression}}; 最佳答案 您需要使用template消歧器,所以编译器会知道它应该解析hello作为模板成员函数的名称,以及后续的和>作为分隔模板参数的尖括号:f.templatehello();//^^^^^^^^ 关于c++-此模板代码中

c++ - 为什么在 GCC/C++ 中弹出 "pragma GCC diagnostic push"警告?

#pragmaGCCdiagnosticpushitpop:warning:expected[error|warning|ignored]afterâ#pragmaGCCdiagnosticâ为什么?我在Linux中使用GCC。我有一个问题,如果我不能使用pop/push,忽略只影响编译的cpp,而不影响其他cpp?如果其他一些包括上限,是否影响它? 最佳答案 #pragmaGCCdiagnosticpush和#pragmaGCCdiagnosticpop是addedingcc4.6.您使用的是旧版本。这些pragma通常与其他#p

c++ - clang 等同于 -rdynamic gcc 标志是什么?

我找不到任何类似的选项可以将所有函数名称包含到最终发布的二进制文件中。还是clang默认执行此操作? 最佳答案 这道题的正确答案是-Wl,-export_dynamic而不是-Wl,--export-dynamic。-Wl,--export-dynamic只有在ELF平台上使用GNU链接器时才是正确的。这个问题是关于OSX的。来源:http://www.opensource.apple.com/source/ld64/ld64-236.3/src/ld/Options.cpp...elseif(strcmp(arg,"-export

c++ - 奇怪的 gcc 错误 : stray '\NNN' in program

我的开源库中弹出了以下问题,我无法弄清楚发生了什么。我的两个用户有类似的(gcc)编译器错误:/home/someone/Source/src/._regex.cpp:1:1:warning:nullcharacter(s)ignored/home/someone/Source/src/._regex.cpp:1:error:stray‘\5’inprogram/home/someone/Source/src/._regex.cpp:1:error:stray‘\26’inprogram/home/someone/Source/src/._regex.cpp:1:error:stray

c++ - "Cannot appear in a constant expression",我需要它作为一个变量,为什么它不让我这样做?

stringconvert_binary_to_hex(stringbinary_value,intnumber_of_bits){bitsetset(binary_value);ostringstreamresult;result在上面的方法中,我将二进制字符串转换为十六进制字符串。由于十六进制值是4位,number_of_bits变量需要是4的倍数,因为对于我正在编写的应用程序,binary_value的范围可能在4位到256位之间.如何让bitset的大小可变?我的导入:#include#include#include#include#include