Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#Actualsamoth

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 (null) pointer.

#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.

#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).

#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.

PARTNERS