简体   繁体   English

禁止显示“使用'X'属性是C ++ 17扩展名”警告

[英]Suppressing “use of the 'X' attribute is a C++17 extension” warnings

I'm using Qt Creator and I have CONFIG += c++17 in my .pro file, and I'm using the nodiscard attribute where appropriate. 我正在使用Qt Creator,并且我的.pro文件中有CONFIG += c++17 ,并且在适当的地方使用了nodiscard属性。 However, the compiler still needlessly warns that use of the '[[nodiscard]]' attribute is a C++17 extension . 但是,编译器仍会不必要地警告use of the '[[nodiscard]]' attribute is a C++17 extension

Is there a way to suppress that particular warning? 有没有一种方法可以消除该特定警告? Or even all warnings of the type "X is a C++XX extension"? 甚至所有类型为“ X是C ++ XX扩展名”的警告? I've looked everywhere for a flag to include in CXXFLAGS without success. 我到处都在寻找将标志包含在CXXFLAGS而没有成功的标志。

I'm using Qt Creator version 4.9.2 and g++ version 8.3.0 我正在使用Qt Creator版本4.9.2和g ++版本8.3.0

Since Qt 5.12 you can use config flag CONFIG += c++17 从Qt 5.12开始,您可以使用配置标志CONFIG += c++17

Before Qt 5.12 you need to add compiler flags through qmake flags: QMAKE_CXXFLAGS += -std=c++17 for GCC & MinGW and QMAKE_CXXFLAGS += /std:c++latest or QMAKE_CXXFLAGS += /std:c++17 <- depends on MSVC compiler you are using. 在Qt 5.12之前,您需要通过qmake标志添加编译器标志:GCC和MinGW的QMAKE_CXXFLAGS += -std=c++17QMAKE_CXXFLAGS += /std:c++latestQMAKE_CXXFLAGS += /std:c++17 < -取决于您使用的MSVC编译器。

Here is Qt qmake manual variable reference for more info 这是Qt qmake手动变量参考,以获取更多信息

And Gerrit code review of task QTBUG-67527 for even more info 有关任务QTBUG-67527的 Gerrit代码审查,甚至更多信息

After you have added this flags: 添加此标志后:

  1. run qmake on the project again 再次在项目上运行qmake

  2. clean your project. 清理您的项目。 (delete shadow build folder if necessary) (如有必要,请删除阴影构建文件夹)

  3. rebuild your project 重建您的项目

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM