[Development] Compiler warnings

Mathias Hasselmann mathias at taschenorakel.de
Fri Oct 17 19:26:56 CEST 2014

Am 17.10.2014 um 18:31 schrieb Thiago Macieira:
> On Friday 17 October 2014 13:06:39 Milian Wolff wrote:
>> enum Foo {
>> Bar = 1, Baz = 2
>> };
>> Foo foo = static_cast<Foo>(3);
>> Now what do you do without a default clause?
> Shoot the developer who abused the API.
> If the function accepts enum values 1 and 2 and you pass a 3, you deserve the
> undefined behaviour.
> That is the same as passing a bool that doesn't contain exactly values 0 or 1
> or passing an uninitialised pointer.
> We have to handle all regular conditions. We don't have to guard against
> stupidity.

I don't think this example has to do with stupidity. To me this just 
seems like a minimal example of typical integration problems that happen 
in real world. Far fetching I'd talk about distributed services, reading 
files written by a different program version, and such. Also Qt already 
deals with such issues where it is obvious:

     const char * QVariant::typeToName(int typeId) [static]
     Converts the int representation of the storage type, typeId, to its
     string representation.

     Returns a null pointer if the type is QVariant::Invalid(obsolete)
     or doesn't exist.

More information about the Development mailing list