Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
t3nsor opened this issue Nov 3, 2023 · 3 comments · Fixed by cplusplus/draft#6906

Comments

@t3nsor
Copy link

t3nsor commented Nov 3, 2023

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
Copy link
Member

CWG2851

@jensmaurer jensmaurer 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 Feb 3, 2024
@t3nsor
Copy link
Author

t3nsor commented Feb 3, 2024

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

@jensmaurer
Copy link
Member

Fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants