Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

std::is_constant_evaluated returns true in C++2b in manifestly runtime functions #55638

Closed
Assignees
cor3ntin
Labels
c++23clang:frontendLanguage frontend issues, e.g. anything involving "Sema"
@jzmaddock

Description

@jzmaddock

Consider the code:

#include<type_traits>#include<cmath>#include<iostream>template<classInteger>constexpr Integerbitwise_sqrt(const Integer& x){// TODO put real code here, doesn't need it for the bug case thoughreturn0;}template<classInteger>constexpr Integerfast_sqrt(const Integer& x){returnstatic_cast<Integer>(std::sqrt(static_cast<double>(x)));}template<classInteger>constexpr Integerget_sqrt(const Integer& x){if(std::is_constant_evaluated())returnbitwise_sqrt(x);returnfast_sqrt(x);}intmain(){unsigned i;  std::cin >> i;  i =get_sqrt(i);  std::cout << i << std::endl;}

Input comes fromstd::cin, I assume we can all agree that in this contextget_sqrt() can not be a constant context. However,std::is_constant_evaluated() is returning true.

Note that:

  1. The issue only occurs when compiling with-std=c++2b.
  2. The issue does not occur prior to clang-14.
  3. The issue does not occur if we use__builtin_is_constant_evaluated() directly.
  4. Reproduced on Ubuntu-22 withubuntu clang version 14.0.0-1ubuntu1

This is a reduced test case fromBoost.Multiprecision BTW.

Metadata

Metadata

Assignees

Labels

c++23clang:frontendLanguage frontend issues, e.g. anything involving "Sema"

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp