Menu

#177 Code completion fails with enum variables defined/declared along with the enum types

Undefined
open
ollydbg
Bug_Report
2015-06-28
2015-06-13
acqn
No
// 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.

Related

Tickets: #176

Discussion

  • ollydbg

    ollydbg - 2015-06-14
    • assigned_to: ollydbg
    • Type: Undefined --> Bug_Report
     
  • ollydbg

    ollydbg - 2015-06-14

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

     
    • acqn

      acqn - 2015-06-16

      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: #176

      • ollydbg

        ollydbg - 2015-06-16

        Hi, acqn, thanks for the reply.

        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.

        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.

         
  • ollydbg

    ollydbg - 2015-06-14

    OK, the second patch fix the further issue, I also add some test case in the log messages, see attachment.

     
    • ollydbg

      ollydbg - 2015-06-15

      Oh, my 0002 patch is not good, I think "enum MyEnum2 : int" should be parsed as a single one.

       
  • ollydbg

    ollydbg - 2015-06-16

    Hi, I don't know, but the following code doesn't compile with g++ (c++11) successfully, see below:

    #include <iostream>
    
    using namespace std;
    
    enum MyEnum2:int {E1 = 0};
    
    extern enum MyEnum2:int my_enum2;
    
    int main()
    {
        cout << "Hello world!" << endl;
        return 0;
    }
    
     
    • acqn

      acqn - 2015-06-26

      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
  • ollydbg

    ollydbg - 2015-06-28

    OK, thanks, since we are not clear what the C++11 standard says, I think I can just follow g++'s way. ^_^.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.