Class-enclosed enum class parse error [message #1824379] |
Tue, 14 April 2020 12:01  |
Eclipse User |
|
|
|
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 #1824407 is a reply to message #1824402] |
Tue, 14 April 2020 18:47   |
Eclipse User |
|
|
|
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 #1824450 is a reply to message #1824410] |
Wed, 15 April 2020 08:39  |
Eclipse User |
|
|
|
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 09:14] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 9.74474 seconds