C++ gnu gcc 如何抑制警告:此声明中忽略了“typedef”[默认启用]
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9587509/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
gnu gcc How to suppress warning: ‘typedef’ was ignored in this declaration [enabled by default]
提问by 2607
I am using GNU gcc 4.6.2 on Fedora 16. I am writing an application using a 3rd party API, after compilation, I got a lot warnings.
我在 Fedora 16 上使用 GNU gcc 4.6.2。我正在使用 3rd 方 API 编写应用程序,编译后,我收到了很多警告。
warning: ‘typedef' was ignored in this declaration [enabled by default]
Just wondering how can I suppress this? I compile my program with -Wall flag.
只是想知道我怎样才能抑制这个?我用 -Wall 标志编译我的程序。
In this doc, http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html, it mentioned something like -Wunused-local-typedefs.
在这个文档http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html 中,它提到了-Wunused-local-typedefs 之类的东西。
I have tried -Wno-unused-local-typedefs, but doesn't work.
我试过-Wno-unused-local-typedefs,但不起作用。
Thanks.
谢谢。
回答by Andres Kievsky
-Wno-unused-local-typedefs works in gcc 4.8 for me.
-Wno-unused-local-typedefs 对我来说适用于 gcc 4.8。
回答by bpw1621
gcc allows you to specify that certain library include paths should be treated as systemlibraries with the -isystem
switch which allows those headers special treatment with respect to the flags you use on the rest of your code. So for example if you have unused local typedefs from using certain Boost libraries in test.cpp
(I ran into this using including the Boost signals2
library recently)
gcc 允许您指定某些库包含路径应被视为系统库,并使用-isystem
开关允许这些头文件对您在其余代码中使用的标志进行特殊处理。因此,例如,如果您在使用某些 Boost 库时有未使用的本地 typedef test.cpp
(我signals2
最近使用包含 Boost库遇到了这个问题)
g++ -o test{,.cpp} -Wall -Wextra -Werror -I /usr/local/boost-1.55.0/include -L /usr/local/boost-1.55.0/lib
and the above does not build cleanly try the following
并且上面没有干净地构建尝试以下
g++ -o test{,.cpp} -Wall -Wextra -Werror -isystem /usr/local/boost-1.55.0/include -L /usr/local/boost-1.55.0/lib
which will (provided the warnings coming from the Boost libraries you are including in test.cpp
are your only problem of course).
这将(如果来自您所包含的 Boost 库的警告test.cpp
当然是您唯一的问题)。
回答by x539
According to the gcc-source-code(gcc/cp/decl.c:4108):
根据 gcc-source-code(gcc/cp/decl.c:4108):
warning (0, "%<typedef%> was ignored in this declaration");
There is no command line flag(that is what the 0 stands for) to suppress this warning in gcc 4.6.2.
在 gcc 4.6.2 中没有命令行标志(即 0 代表什么)来抑制此警告。
回答by Johan
As -Wunused-local-typedef
is part of -Wall
, make sure you don't have -Wall
after -Wno-unused-local-typedef
. If you do, -Wall
just turns the option back on again.
作为-Wunused-local-typedef
的一部分-Wall
,请确保您没有-Wall
after -Wno-unused-local-typedef
。如果这样做,-Wall
只需再次打开该选项即可。
回答by Fading
This GCC warning means that your typedef maybe duplicated and you should remove typedef keyword instead. For example:
这个 GCC 警告意味着您的 typedef 可能重复,您应该删除 typedef 关键字。例如:
typedef enum class Something {
THING1,
THING2,
} Something;
This code above is type duplicate, because enum class is defined as type already. So you must remove typedef keyword as well as Something at the end too!
上面的代码是类型重复的,因为枚举类已经定义为类型。所以你必须删除 typedef 关键字以及最后的东西!
回答by guest
In c++17, you should use maybe_unused, please see
在c++17中,你应该使用maybe_unused,请看
http://en.cppreference.com/w/cpp/language/attributes
http://en.cppreference.com/w/cpp/language/attributes
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0212r0.pdf
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0212r0.pdf
(sorry, I could't post an example, as it's considered as badly indented by stackoverflow)
(对不起,我不能发布一个例子,因为它被认为是被stackoverflow严重缩进的)