开发者

g++ C++0x enum class Compiler Warnings

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
};

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__((visib开发者_如何学JAVAility("hidden")))  MyClass;

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).

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.


You can pass the -Wno-attributes flag to turn the warning off.

(It's probably a bug in gcc?)


It works for me with g++ 4.8.2 the following way:

enum class MyEnum : unsigned int
__attribute__((visibility("default")))
{
    One = 1,
    Two = 2
};

(change the position of the attribute declaration)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜