草庐IT

warn_unused_result

全部标签

c++ - 为什么 std::bind1st 被认为是 "almost unusable"?

在关于boost::bind的对话中,有人指出std::bind1st存在于C++03中,但它“几乎无法使用”。我找不到任何可靠的证据来支持这一点。Theboost::binddocumentation说:boost::bindisageneralizationofthestandardfunctionsstd::bind1standstd::bind2nd.Itsupportsarbitraryfunctionobjects,functions,functionpointers,andmemberfunctionpointers,andisabletobindanyargumentt

c++ - 如何在 GCC 中禁用#warning 消息?

GCC中有一个名为#warning的预处理器指令,它只是在编译时使用附加的字符串发出警告。海湾合作委员会documentation说这可以用-Wno-cpp标志禁用。但是,此标志似乎不起作用。我在用海湾合作委员会4.4.3。一个简单的测试用例是这样的:#include#warning"Hello"intmain(){}结果是:$g++warn.ccwarn.cc:2:2:warning:#warning"Hello"$g++warn.cc-Wno-cppwarn.cc:2:2:warning:#warning"Hello"文档有错吗? 最佳答案

c++ - 如何在模板参数中将 std::result_of 转换为 decltype

在CppCon2015上,来自Microsoft的S.Lavavejsaid避免使用result_of.但我的情况是,我似乎无法找到合适的替代方案。考虑以下代码。有没有办法改变std::result_of::type使用decltype相反?#include#include#includetemplatestructNopErrCB{constexprToperator()()const{returnT();}};templatestructSafeTaskWrapper{Funcf;ErrCBerrCB;templateautooperator()(T&&...args)->decl

c++ - 为什么 std::result_of 不适用于 lambda?

我设法将我的案例简化为以下最简单的代码:#includeautocall(constauto&f)->typenamestd::result_of::type{returnf();}intmain(){returncall([]{return0;});}gcc-4.9.2和gcc-5.0.0都不编译!两者都认为“调用”应该返回一个lambda函数!不要弄清楚“调用”返回一个int。这是编译器中的错误还是我的C++关闭了?非常感谢。 最佳答案 您的代码不是有效的C++,因为函数参数类型不能是auto,此语法已为ConceptsLite

c++ - 警告 : #warning qopenglfunctions. h 与 GLEW 不兼容,GLEW 定义将未定义 [-Wcpp]

我正在配置一个与glut一起工作的程序来与Qt一起工作。我正在使用Qt5.1.1。并且似乎从Qt4到Qt5已经丢失了一些openGL功能。在我的程序中,我创建了一个QOpenGLContext并尝试使用vbo渲染到QWindow。vbo部分工作正常。程序的其他一些部分依赖于glew。我在运行程序时收到以下警告#warningqopenglfunctions.hisnotcompatiblewithGLEW,GLEWdefineswillbeundefined[-Wcpp]#warningTouseGLEWwithQt,donotincludeorafterglew.h[-Wcpp]屏幕

c++ - 为什么 "cc1plus: warning: unrecognized command line option"选项的 "no-"仅在出现另一个警告时由 g++ 标记?

>catwarning.cpp#pragmafoobar>catno_warning.cpp#pragmamessage"foobar">g++-Wall-Wno-foobar-cwarning.cppwarning.cpp:1:0:warning:ignoring#pragmafoobar[-Wunknown-pragmas]cc1plus:warning:unrecognizedcommandlineoption"-Wno-foobar"[enabledbydefault]>g++-Wall-Wno-foobar-cno_warning.cppno_warning.cpp:1:17

c++ - 使用 cmake 添加 _CRT_SECURE_NO_WARNINGS 定义

是否可以使用cmake添加_CRT_SECURE_NO_WARNINGS预处理器定义?add_definitions(-CRT_SECURE_NO_WARNINGS)add_definitions(-_CRT_SECURE_NO_WARNINGS)add_definitions(_CRT_SECURE_NO_WARNINGS)这些是我到目前为止尝试过的。这些尝试都没有成功。 最佳答案 使用这个:if(MSVC)add_definitions(-D_CRT_SECURE_NO_WARNINGS)endif()参见here获取官方文档。

c++ - 循环 : future iterations overwrite results of previous iterations 中的 If-else 条件

我尝试在items列表中突出显示selectedItem及其children。constQListitems=/*...*/;Item*selectedItem=/*...*/;Q_FOREACH(Item*item,items){if(selectedItem==item){item->setHighlightEnabled(true);//Highlightselecteditem}else{item->setHighlightEnabled(false);//De-highlightotheritems}}item->setHighlightEnabled方法递归地对子项执行相同

c++ - 创建自定义#warning 标志

我正在构建一个商业应用程序,我们正在使用一些GPL代码来帮助我们。如何添加#warning或#error语句,以便在为调试构建代码时发出警告,但在为发布构建时抛出错误?我能做到:#warningthiscodeisreleasedunderaCCLlicensingscheme,seeSource_Code_License.rtf#warningthiscodeisnotLGPL-compliant#warningthiscodewascopiedverbatimfromaGPLicensedfile在文件的开头,但我可以做得更好吗?如果包含文件,是否有更好的标记文件的方法?我正在使用

c++ - 通过 bash 脚本查找和修改函数定义 (C++)

目前我正在从事一个相当大的项目。为了提高我们代码的质量,我们决定对每个函数强制执行返回值(错误代码)处理。GCC支持关于函数返回值的警告,但是函数定义必须在以下标志之前。static__attribute__((warn_unused_result))ErrorCodetest(){/*codegoeshere*/}我想实现一个解析整个源代码并发出警告的bashscript,以防万一__attribute__((warn_unused_result))不见了。请注意,所有需要这种修改的函数都会返回一个名为ErrorCode的类型。您认为这可以通过bash脚本实现吗?