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

I will refactor my terrible mess under a C ++ alias of type psuedo-enums for new transition types like C ++ 0x because they are more readable. Anyway, I use them in exported classes, so I will explicitly mark them for export:

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

Compiling with g ++ gives the following warning:

type attributes are ignored after the type is already defined

This seems very strange since, as far as I know, this warning is intended to prevent actual errors, such as:

 class __attribute__((visibility("default"))) MyClass { }; class __attribute__((visibility("hidden"))) MyClass; 

Of course, I do not explicitly do this, since I only noted the visibility attributes in the definition of the enum class , and I do not redefine it or declare it anywhere (I can duplicate this error with a single file).

Ultimately, I cannot make this bit of code really the cause of the problem, except that if I change the value and recompile the user without recompiling the shared library, the consumer passes the new values ​​and the shared library does not know what to do with them (although I would not expect this to work in the first place).

Am I too pedantic? Can this be safely ignored? I suspect it is, but at the same time, this error prevents me from compiling with Werror , which makes me uncomfortable. I would really like this problem to disappear.

+7
c ++ c ++ 11 compiler-warnings g ++
source share
2 answers

You can pass the -Wno-attributes flag to disable the warning.

(This is probably a bug in gcc?)

+3
source share

It works for me with g ++ 4.8.2 as follows:

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

(reposition attribute )

+1
source share

All Articles