Does not compile just fine (though it does compile) with gcc:
warning: converting 'false' to pointer type for argument 1 of 'Ptr::Ptr(void*, bool)'
Strictly speaking, your compiler is correct about doing this conversion. The standard says: (4.5-6) "A prvalue of type bool can be converted to a prvalue of type int, with false becoming zero and true becoming one." and (4.10) "A null pointer constant is an integral constant expression (5.19) prvalue of integer type that evaluates to zero or a prvalue of type std::nullptr_t. A null pointer constant can be converted to a pointer type".
This explains why it is legal for false, but not for true (the former is a null pointer constant, the latter is not). It's converting a bool constant to an integer constant, which happens to be a null pointer constant, which it converts to a (null) pointer.
Show differencesHistory of post edits
#3samoth
Posted 21 June 2012 - 03:48 AM
Does not compile just fine (though it does compile) with gcc:
warning: converting 'false' to pointer type for argument 1 of 'Ptr::Ptr(void*, bool)'
Strictly speaking, your compiler is correct about doing this conversion. The standard says: (4.5-6) "A prvalue of type bool can be converted to a prvalue of type int, with false becoming zero and true becoming one." and (4.10) "A null pointer constant is an integral constant expression (5.19) prvalue of integer type that evaluates to zero or a prvalue of type std::nullptr_t. A null pointer constant can be converted to a pointer type".
This explains why it is legal for false, but not for true (the former is a null pointer constant, the latter is not). It's converting a bool constant to an integer constant, which happens to be a null pointer constant, which it converts to a pointer.
warning: converting 'false' to pointer type for argument 1 of 'Ptr::Ptr(void*, bool)'
Strictly speaking, your compiler is correct about doing this conversion. The standard says: (4.5-6) "A prvalue of type bool can be converted to a prvalue of type int, with false becoming zero and true becoming one." and (4.10) "A null pointer constant is an integral constant expression (5.19) prvalue of integer type that evaluates to zero or a prvalue of type std::nullptr_t. A null pointer constant can be converted to a pointer type".
This explains why it is legal for false, but not for true (the former is a null pointer constant, the latter is not). It's converting a bool constant to an integer constant, which happens to be a null pointer constant, which it converts to a pointer.
#2samoth
Posted 21 June 2012 - 03:46 AM
Does not compile just fine (though it does compile) with gcc:
warning: converting 'false' to pointer type for argument 1 of 'Ptr::Ptr(void*, bool)'
Strictly speaking, your compiler is correct about doing this conversion. The standard says: (4.5-6) "A prvalue of type bool can be converted to a prvalue of type int, with false becoming zero and true becoming one." and (4.10) "A null pointer constant can be converted to a pointer type".
This explains why it is legal for false, but not for true (the former is a null pointer constant, the latter is not).
warning: converting 'false' to pointer type for argument 1 of 'Ptr::Ptr(void*, bool)'
Strictly speaking, your compiler is correct about doing this conversion. The standard says: (4.5-6) "A prvalue of type bool can be converted to a prvalue of type int, with false becoming zero and true becoming one." and (4.10) "A null pointer constant can be converted to a pointer type".
This explains why it is legal for false, but not for true (the former is a null pointer constant, the latter is not).
#1samoth
Posted 21 June 2012 - 03:45 AM
Does not compile just fine (though it does compile) with gcc:
warning: converting 'false' to pointer type for argument 1 of 'Ptr::Ptr(void*, bool)'
Strictly speaking, your compiler is correct about doing this conversion. The standard says: (4.5-6) "A prvalue of type bool can be converted to a prvalue of type int, with false becoming zero and true becoming one." and (4.10) "A null pointer constant can be converted to a pointer type".
This explains why it is legal for false, but not for true.
warning: converting 'false' to pointer type for argument 1 of 'Ptr::Ptr(void*, bool)'
Strictly speaking, your compiler is correct about doing this conversion. The standard says: (4.5-6) "A prvalue of type bool can be converted to a prvalue of type int, with false becoming zero and true becoming one." and (4.10) "A null pointer constant can be converted to a pointer type".
This explains why it is legal for false, but not for true.