Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Class-enclosed enum class parse error(Eclipse (v4.15.0) CDT (v9.11.0.202003091030) fails to properly parse an enum class's elements when that class is forward declared within a container class)
Class-enclosed enum class parse error [message #1824379] Tue, 14 April 2020 16:01 Go to next message
Mark Odell is currently offline Mark OdellFriend
Messages: 6
Registered: April 2020
Junior Member
I have attached a very small C++ source and header file project as an example. Notice how RegAddr::CTRL_REG1 is declared as "could not be resolved" yet the code is C++11 compliant and compiles without a warning.

Anyone else seen this? Work-arounds?

Thanks,

- Mark
Re: Class-enclosed enum class parse error [message #1824402 is a reply to message #1824379] Tue, 14 April 2020 21:21 Go to previous messageGo to next message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
Actually, your example could have been much smaller.
You only needed about 10-15 lines max.

There are errors in your code.
It's a wonder that it compiles.

First of all, enum class AccelLis2de12::RegAddr : uint8_t { ... } RegAddr; is declaring a variable named RegAddr
RegAddr::xxx constructs afterwards, such as RegAddr::CTRL_REG1, don't make any sense.

You probably meant to use typedef enum class AccelLis2de12::RegAddr : uint8_t { ... } RegAddr;

Secondly, even using a typedef seems to be causing problems.
I changed your code to use a typedef and changed the name to RegAddr_x just to be unique.
That is, typedef enum class AccelLis2de12::RegAddr : uint8_t { ... } RegAddr_x;

All references to the enum must be qualified thusly, AccelLis2de12::RegAddr
Full qualification is not necessary within member definitions but safer.

index.php/fa/37825/0/

It's possible to use the typedef instead.
index.php/fa/37826/0/

[Updated on: Tue, 14 April 2020 22:12]

Report message to a moderator

Re: Class-enclosed enum class parse error [message #1824407 is a reply to message #1824402] Tue, 14 April 2020 22:47 Go to previous messageGo to next message
Mark Odell is currently offline Mark OdellFriend
Messages: 6
Registered: April 2020
Junior Member
The trailing } RegAddr; was a copy/paste from some old C code sorry about that. But really all that did was allocate a variable in the source file call RegAddr. I have removed it and the parser still screws up. It wasn't used and does not conflict with the enum namespace. Either way, with or without the RegAddr variable it's still legal C++11 code and compiles without error with this build line: g++ -std=c++11 -pedantic -Wall -Wextra -ggdb3 -Og -o accel accel.cpp

All the enumerations within enum class AccelLis2de12::RegAddr : uint8_t {} do make sense and are used properly and show up properly in the debugger. We don't use typedefs in C++ very often because the tag name is also a typename in C++. If we did need an alias we would use the using directive anyway, e.g. using reg_t = AccelLis2de12::RegAddr;. The typedef is for legacy code only. Remember, in C++ we can write:

enum Foo { ... };
Foo foo;
instead of enum Foo foo; which is allowed but unnecessary.

Lastly, within a method of AccelLis2de12 the entire body of the method including the parameter list is in that namespace and therefore does not require, nor does one typically provide, the class name due to visual clutter imposed by doing so. I do not have any references to the enum values outside the scope of the class itself, because it's protected, and so no full qualifications are needed. Incidentally, adding the redundant class name does not help the Eclipse parser get it right either.

The code is fully compliant as written, compiles without warnings with the -pedantic flag, and debugs as expected. The *only* issue I had with this example is Eclipse's bogus parsing of the legal C++ code. Thank you for taking the time to look at my code.

Re: Class-enclosed enum class parse error [message #1824410 is a reply to message #1824407] Wed, 15 April 2020 02:07 Go to previous messageGo to next message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
You asked for a workaround and got it.
It clearly works for me.
Why it doesn't for you only you can answer.

If you want to argue the finer language points this isn't the proper forum.
Take it up on stackoverflow or elsewhere.
Exchanges of this nature rarely solve anything.
If you still think there's an issue file a bug report.

Before you do that, I suggest you make a smaller example.
Doing so might lead you to the answer why it doesn't work for you.


[Updated on: Wed, 15 April 2020 02:46]

Report message to a moderator

Re: Class-enclosed enum class parse error [message #1824450 is a reply to message #1824410] Wed, 15 April 2020 12:39 Go to previous message
Mark Odell is currently offline Mark OdellFriend
Messages: 6
Registered: April 2020
Junior Member
I'm not sure what I did to get you so upset with me. I'm not arguing the finer points of C++ I'm telling you that the Eclipse CDT does not parse legal, correct C++ code properly. I've updated and reduced my example to avoid any language fine points. The example project now shows that the CDT parser is incorrect in handling the enum class within the containing class yet gets it right when the enum is outside the class. Emacs and Vscode get the parsing correctly in both cases and of course so does the g++ compiler. Gdb also shows how the example plays out...

Starting program: /tmp/accel/accel

Breakpoint 1, main () at accel.cpp:23

(gdb) ptype accel
type = struct AccelLis2de12 {
public:
bool inn(AccelLis2de12::RegAddrInside);
bool out(RegAddrOutside);
}

(gdb) ptype AccelLis2de12::RegAddrInside
type = enum class AccelLis2de12::RegAddrInside : unsigned char
{AccelLis2de12::RegAddrInside::ONE, AccelLis2de12::RegAddrInside::TWO}

(gdb) ptype RegAddrOutside
type = enum class RegAddrOutside : unsigned char
{RegAddrOutside::ONE, RegAddrOutside::TWO}

So, I believe this is a bug and am looking for confirmation. I'd like to help make Eclipse CDT better here, that's all.

[Updated on: Wed, 15 April 2020 13:14]

Report message to a moderator

Previous Topic:GDB error in Eclipse
Next Topic:upload using AVRDUDE
Goto Forum:
  


Current Time: Fri Mar 29 13:46:07 GMT 2024

Powered by FUDForum. Page generated in 0.03009 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top