Closed
Bug 859874
Opened 12 years ago
Closed 12 years ago
mfbt/TypedEnum.h on non-C++11 compilers disables all arithmetic operators
Categories
(Core :: MFBT, defect)
Tracking
()
RESOLVED
INVALID
People
(Reporter: bjacob, Unassigned)
Details
Attachments
(1 file)
271 bytes,
text/x-c++src
|
Details |
I think it shouldn't. Don't C++11 typed enums have arithmetic operators?
The idea is that people should be able to do
for(MyEnumType n = 0; n < SomeBigEnumValue; ++n)
instead of having to use a plain integer as loop index. That would further cement the strong typing around such code, instead of forcing people to use plain integers and cast them.
Use case in bug 852734.
Comment 1•12 years ago
|
||
Do you have a test case?
Reporter | ||
Comment 2•12 years ago
|
||
Tested with G++4.6. Compiling in non-C++11 mode, I get:
$ g++ ehsan.cpp -I .
ehsan.cpp: In function ‘int main()’:
ehsan.cpp:14:9: error: no match for ‘operator++’ in ‘++n’
ehsan.cpp:14:9: note: candidates are:
ehsan.cpp:8:1: note: int& operator++(MyEnumType::Enum&)
ehsan.cpp:8:1: note: no known conversion for argument 1 from ‘MyEnumType’ to ‘MyEnumType::Enum&’
ehsan.cpp:8:1: note: int operator++(MyEnumType::Enum&, int)
ehsan.cpp:8:1: note: candidate expects 2 arguments, 1 provided
That's what I'm referring to.
On a separate note, compiling in C++11 mode, I get errors that suggest that something is wrong either in G++ 4.6 or in our C++11 codepath there... I don't know C++11 enums so I can't tell.
$ g++ ehsan.cpp -I . --std=c++0x
ehsan.cpp:3:1: warning: elaborated-type-specifier for a scoped enum must not use the ‘class’ keyword [enabled by default]
ehsan.cpp:3:1: error: use of enum ‘MyEnumType’ without previous declaration
ehsan.cpp:3:1: error: expected unqualified-id before ‘:’ token
ehsan.cpp: In function ‘int main()’:
ehsan.cpp:12:7: error: ‘MyEnumType’ was not declared in this scope
ehsan.cpp:12:18: error: expected ‘;’ before ‘n’
ehsan.cpp:13:7: error: ‘n’ was not declared in this scope
ehsan.cpp:13:11: error: ‘MyEnumType’ is not a class, namespace, or enumeration
Reporter | ||
Comment 3•12 years ago
|
||
Erm. Replacing the typed enum by a plain C++98 enum there, I get "error: no match for ‘operator++’ in ‘++n’".
So I guess that ++n for an enum was never allowed. -> INVALID.
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → INVALID
Comment 4•12 years ago
|
||
Yep, which is why I asked for a test case. ;-)
You need to log in
before you can comment on or make changes to this bug.
Description
•