Skip to content

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

Description

@t3nsor

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,
  • [...]

Activity

  1. jensmaurer commented on Feb 3, 2024

    @jensmaurer
    Member
  2. changed the title [-][expr.const] Non-narrowing floating-point conversions should be allowed in converted constant expressions[/-] [+]CWG2851 [expr.const] Non-narrowing floating-point conversions should be allowed in converted constant expressions[/+] on Feb 3, 2024
  3. t3nsor commented on Feb 3, 2024

    @t3nsor
    Author

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

  4. jensmaurer commented on Feb 3, 2024

    @jensmaurer
    Member

    Fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions