cplusplus / CWG

Core Working Group
23 stars 7 forks source link

CWG2851 [expr.const] Non-narrowing floating-point conversions should be allowed in converted constant expressions #456

Closed t3nsor closed 3 months ago

t3nsor commented 8 months ago

Full name of submitter: Brian Bi

Reference (section label): [expr.const]

Issue description: Prior to the adoption of P1907R1, which allowed non-type template parameters to be of floating-point type, there was nothing in the language that could require a converted constant expression of floating-point type. Since P1907R1 has been adopted, it is surprising that a double value can't be passed as a template argument for a template parameter of type long double.

The rules for narrowing floating-point conversions, [dcl.init.list]/7.2, might not be strict enough. We might want to disallow any conversion where the destination type can't represent the source value exactly. Or we might want to be even more strict and disallow conversion to lower rank even when the source value can be represented exactly.

Suggested resolution: Add two bullets after [expr.const]/12.7:

  • [...]
  • integral promotions,
  • integral conversions other than narrowing conversions,
  • floating-point promotions,
  • floating-point conversions where the source value can be represented exactly in the destination type,
  • null pointer conversions from std::nullptr_t,
  • [...]

Alternative suggested resolution: Add two bullets after [expr.const]/12.7:

  • [...]
  • integral promotions,
  • integral conversions other than narrowing conversions,
  • floating-point promotions,
  • floating-point conversions where the floating-point conversion rank of the destination type is greater than or equal to that of the source type,
  • null pointer conversions from std::nullptr_t,
  • [...]
jensmaurer commented 5 months ago

CWG2851

t3nsor commented 5 months ago

The link back to GitHub from the issue page is wrong; it currently says #490

jensmaurer commented 5 months ago

Fixed.