// even in C++98 enum MyEnum // same whether unnamed { /* ... */ } my_enum; // not CC'ed // in C++11, you can write weirder code extern enum MyEnum2 : int my_enum2; // type of my_enum2 is 'enum MyEnum2', but CC insists 'int'
I came across this when I was messing around with [#176].
Although I have never seen such 'weird' code in any practical design, and I even doubt if it could be, but it's still legal and possible.
The first part of the bug can be fixed easily, but I don't intend to fix the second part very soon, because I don't know how we handle extern statement, can we just skip them? Since we can always find them(the real definition) in some source code.
The patch is against on patch of SF #176 (https://sourceforge.net/p/codeblocks/tickets/176/)
For the sake of coherence:
I used 'extern' in order to demonstrate the issue with declarations. Variables' definitions (usually without 'extern') are affected as well.
That's to say, you may see there are two closely related issues:
(1) that CC fails with certain forms of definitions of enum variables (C++98 and later).
(2) that CC fails with certain forms of declarations of enum variables (C++11 and later).
It is C++11 allowing forward declarations of enums and enum variables without duplicating the definitions of the enum types that makes the second part a new issue.
That's all I can hopefully help at the moment. Perhaps I should have integrated the second part with [#176] instead...
Related
Tickets:
#176Hi, acqn, thanks for the reply.
I'm not fully understand this. In my reply Link, I mean that the code snippet is not a valid c++ statement, because it can't be complied by the g++ compiler with c++11 command line option added.
So, can you give some minimal example about this kind of bug. I mean I need a minimal code which can at least build successfully under g++ with c++11 option enabled.
OK, the second patch fix the further issue, I also add some test case in the log messages, see attachment.
Oh, my 0002 patch is not good, I think "enum MyEnum2 : int" should be parsed as a single one.
Hi, I don't know, but the following code doesn't compile with g++ (c++11) successfully, see below:
Hi, sorry for the long delay.
The declaration syntax in question (extern enum MyEnum2:int my_enum2) does work with clang (C++11). It might just be an "extension" ("feature" or "bug") of clang, or a corner piece that g++ has just overlooked.
Unfortunately, I now have zero confidence to assert which compiler (g++ or clang) is correct (as in "standard-conforming") on this...
Last edit: acqn 2015-06-26
OK, thanks, since we are not clear what the C++11 standard says, I think I can just follow g++'s way. ^_^.