Is it legal to re-declare a member class after defining it?
Asked Answered
Q

1

0

I have a problem with compiling boost.bimap library. My test program is a blank main function and only one include directive(like #include <boost/bimap.hpp>). After some investigations I found out that preprocessor had made some interesting constructions from header file like:

struct A { struct B{}; struct B; };

I don't know if this is correct or not, but gcc accepts it while clang and icc don't. Who is right and what can I do to compile programs with bimap library? Unfortunately, I can't use gcc in this case.

Quietude answered 22/9, 2015 at 8:28 Comment(6)
Everything sounds to me like you've got errors somewhere else, and this is the result from the pre-processor standpoint.Kaufman
This question has nothing to do with Boost.Bimap. Just because you're using it in other parts of the code doesn't make it relevant to this.Earleenearlene
What exactly is the error you are getting? (And why didn't you tell us it in the first place?)Earleenearlene
invalid redeclaration of nested class BOOST_BIMAP_SYMMETRIC_METADATA_ACCESS_BUILDER this error I am gettingQuietude
That's not exactly the error you are getting, because you left out the part that says [-Werror,-Wredeclared-class-member] which is the important part. That is what shows you are using -Werror, and can solve the problem by not doing that.Earleenearlene
@JonathanWakely, you are right, thank you for your attention. Problem was solved and we have nothing to do hereQuietude
E
11

struct B{}; defines a nested class, then struct B; is a re-declaration of the same nested class.

GCC is wrong to accept the code (bug report), because the standard says in [class.mem]:

A member shall not be declared twice in the member-specification, except that a nested class or member class template can be declared and then later defined,

In your case the nested class is defined then declared, which is not allowed, so Clang and ICC are correct to give a diagnostic. However, when I test it they only give a warning, not an error, so maybe you are using -Werror, in which case stop doing that and the code should compile.

The problem in the Boost.Bimap code is a known bug.

Earleenearlene answered 22/9, 2015 at 9:57 Comment(1)
I linked to this answer from my question hereUnquestioned

© 2022 - 2024 — McMap. All rights reserved.