Topic: static_cast<int>(bool)


Author: Michael R Cook <mcook@cognex.com>
Date: 1997/01/06
Raw View
Here's an excerpt from the draft standard, [expr.static.cast]:

6 The  inverse  of any standard conversion sequence (_conv_), other than
  the lvalue-to-rvalue (_conv.lval_),  array-to-pointer  (_conv.array_),
  function-to-pointer  (_conv.func_),  and boolean (_conv.bool_) conver-
  sions, can be performed explicitly using static_cast  subject  to  the
  restriction  that the explicit conversion does not cast away constness
  (_expr.const.cast_), and the following additional rules  for  specific
  cases:

Why are conversions from boolean disallowed?
Does that paragraph mean to disallow static_cast<int>(bool)?
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: Jason Merrill <jason@cygnus.com>
Date: 1997/01/06
Raw View
>>>>> Michael R Cook <mcook@cognex.com> writes:

> Here's an excerpt from the draft standard, [expr.static.cast]:
> 6 The  inverse  of any standard conversion sequence (_conv_), other than
>   the lvalue-to-rvalue (_conv.lval_),  array-to-pointer  (_conv.array_),
>   function-to-pointer  (_conv.func_),  and boolean (_conv.bool_) conver-
>   sions, can be performed explicitly using static_cast  subject  to  the
>   restriction  that the explicit conversion does not cast away constness
>   (_expr.const.cast_), and the following additional rules  for  specific
>   cases:

> Why are conversions from boolean disallowed?

They aren't.

> Does that paragraph mean to disallow static_cast<int>(bool)?

No, since bool->int is also a standard conversion sequence.

Jason
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]





Author: Alexandre Oliva <oliva@dcc.unicamp.br>
Date: 1997/01/07
Raw View
Michael R Cook writes:

> Here's an excerpt from the draft standard, [expr.static.cast]:
> 6 The  inverse  of any standard conversion sequence (_conv_), other than
>   the lvalue-to-rvalue (_conv.lval_),  array-to-pointer  (_conv.array_),
>   function-to-pointer  (_conv.func_),  and boolean (_conv.bool_) conver-
>   sions, can be performed explicitly using static_cast  subject  to  the
>   restriction  that the explicit conversion does not cast away constness
>   (_expr.const.cast_), and the following additional rules  for  specific
>   cases:

> Why are conversions from boolean disallowed?

They are not.

> Does that paragraph mean to disallow static_cast<int>(bool)?

No, it is a standard conversion, not the inverse of a standard
conversion.  It is defined in [conv.prom].  I guess it is there to
prevent converting a boolean to a pointer (what would true mean after
having been converted to a pointer?)

--
Alexandre Oliva
mailto:oliva@dcc.unicamp.br
Universidade Estadual de Campinas, SP, Brasil
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]