Type conversion operator and switch
-
Folgendes: http://ideone.com/IHsBfD
Warum? Das Objekt ist non-const also auch die non-const Version, oder nicht?
Compiler-Bug?
-
Compiler-Bug?
Zumindest ist der Compiler inkonsequent. Folgende Definition kompiliert:
int i = f;Und genau diese Deklaration sollte auch stattfinden um die Konvertierungsfunktion zu bestimmen:
An expression
ecan be implicitly converted to a typeTif and only if the declarationT t=e;is well-formed, for some invented temporary variable `t[..] An expressioneof class typeEappearing in such a context is said to be contextually implicitly converted to a specified typeTand is well-formed if and only ifecan be implicitly converted to a typeTthat is determined as follows:Eis searched for conversion functions whose return type is *cv*Tor reference to *cv*Tsuch thatTis allowed by the context. There shall be exactly one suchT` .Es gibt genau ein solches
T,int.Laut Overload-Resolution ist aber AFAICS die non-const Version besser, wegen dem Objekt-Argument.
-
Arcoth schrieb:
Compiler-Bug?
Zumindest ist der Compiler inkonsequent. Folgende Definition kompiliert:
int i = f;Ja, das fiel mir auch auf.
[...]
Das denke ich auch. Es sollte gehen.
Aber sowohl bei meinem TDM-GCC und dem GCC in ideone gehts nicht.
-
n3337 schrieb:
6.4.2 The switch statement
[...]
The condition shall be of integral type, enumeration type, or of a class type for which a single non-explicit conversion function to integral or enumeration type exists (12.3).Im Gegensatz zu C ist switch typmäßig nicht auf int beschränkt.
-
camper schrieb:
n3337 schrieb:
6.4.2 The switch statement
[...]
The condition shall be of integral type, enumeration type, or of a class type for which a single non-explicit conversion function to integral or enumeration type exists (12.3).Im Gegensatz zu C ist switch typmäßig nicht auf int beschränkt.
Und das heißt jetzt genau was?
-
camper zitiert glatt N3337, und ich habe in N3797 nachgeschaut - wo die zitierte Regel natürlich nicht so enthalten ist, da sie geändert wurde.
Läuft es wenn du -std=c++1y angibst? Denn in C++14 wird die condition contextually implicitly converted, und da ist die Regel anders formuliert.
Edit: Ja, läuft.
-
camper, bist du headmyshoulder? Die Altersangabe stimmt perfekt - seine Beschreibung passt auch. Sein Artikel passt ebenfalls.

Edit: Ich hab' ihn! camper ist Karsten Ahnert!
Edit²: Nein, ist er nicht. http://www.c-plusplus.net/forum/p1334574#1334574
Oder hat er versucht seine Identität durch eine etwas uneloquentere und unbeholfene Ausdrucksweise und falsche Informationen zu verschleiern?