g ++ C ++ 0x枚举类编译器警告 [英] g++ C++0x enum class Compiler Warnings
问题描述
我一直在将C ++类型安全的伪枚举的可怕混乱重构为新的C ++ 0x类型安全的枚举,因为它们的可读性更高。无论如何,我在导出的类中使用了它们,因此我将它们明确标记为要导出:
I've been refactoring my horrible mess of C++ type-safe psuedo-enums to the new C++0x type-safe enums because they're way more readable. Anyway, I use them in exported classes, so I explicitly mark them to be exported:
enum class __attribute__((visibility("default"))) MyEnum : unsigned int
{
One = 1,
Two = 2
};
使用g ++编译会产生以下警告:
Compiling this with g++ yields the following warning:
类型属性在定义类型后被忽略
type attributes ignored after type is already defined
这似乎很奇怪,因为到目前为止据我所知,该警告旨在防止出现实际错误,例如:
This seems very strange, since, as far as I know, that warning is meant to prevent actual mistakes like:
class __attribute__((visibility("default"))) MyClass { };
class __attribute__((visibility("hidden"))) MyClass;
当然,我显然没有这样做,因为我只在 enum类
的定义,并且我没有在其他任何地方重新定义或声明它(我可以用一个文件复制此错误)。
Of course, I'm clearly not doing that, since I have only marked the visibility attributes at the definition of the enum class
and I'm not re-defining or declaring it anywhere else (I can duplicate this error with a single file).
最终,我无法使这段代码真正引起问题,但事实是,如果我更改值并重新编译使用者而不重新编译共享库,消费者传递了新的价值,而共享库不知道如何处理它们(尽管我不希望它首先发挥作用)。
Ultimately, I can't make this bit of code actually cause a problem, save for the fact that, if I change a value and re-compile the consumer without re-compiling the shared library, the consumer passes the new values and the shared library has no idea what to do with them (although I wouldn't expect that to work in the first place).
我太学究了吗?可以安全地忽略这一点吗?我怀疑是这样,但同时,出现此错误使我无法使用 Werror
进行编译,这使我感到不舒服。我真的很想看到这个问题消失。
Am I being way too pedantic? Can this be safely ignored? I suspect so, but at the same time, having this error prevents me from compiling with Werror
, which makes me uncomfortable. I would really like to see this problem go away.
推荐答案
您可以传递 -Wno属性
标志以关闭警告。
You can pass the -Wno-attributes
flag to turn the warning off.
(可能是gcc中的错误?)
(It's probably a bug in gcc?)
这篇关于g ++ C ++ 0x枚举类编译器警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!