Skip to content

Clang rejects constant expression in requires-clause as 'non-constant expression', which is a misleading diagnostic #81333

@cjdb

Description

@cjdb

Code

template <int __v> struct integral_constant {
  static const int value = __v;
};
template <class _From, class _To>
constexpr bool is_convertible_v = __is_convertible(_From, _To);
template <class _Tp>
constexpr bool is_copy_constructible_v = __is_constructible(_Tp, _Tp);
template <class...> class tuple;
template <class T0> struct tuple<T0> {
  template <class U0>
    requires is_copy_constructible_v<U0>
  tuple(U0);
};
struct ConvertibleFrom;
static_assert(is_convertible_v<tuple<int>, tuple<ConvertibleFrom>>);

Command line

clang++ -std=c++20 file.cpp

Diagnostic

file.cpp:11:14: error: substitution into constraint expression resulted in a non-constant expression
   11 |     requires is_copy_constructible_v<U0>
      |              ^~~~~~~~~~~~~~~~~~~~~~~~~~~
file.cpp:7:42: note: while checking constraint satisfaction for template 'tuple<int>' required here
    7 | constexpr bool is_copy_constructible_v = __is_constructible(_Tp, _Tp);
      |                                          ^~~~~~~~~~~~~~~~~~
file.cpp:7:42: note: in instantiation of function template specialization 'tuple<int>::tuple<tuple<int>>' requested here
file.cpp:11:14: note: in instantiation of variable template specialization 'is_copy_constructible_v<tuple<int>>' requested here
   11 |     requires is_copy_constructible_v<U0>
      |              ^
file.cpp:11:14: note: while substituting template arguments into constraint expression here
   11 |     requires is_copy_constructible_v<U0>
      |              ^~~~~~~~~~~~~~~~~~~~~~~~~~~
file.cpp:5:62: note: while checking constraint satisfaction for template 'tuple<ConvertibleFrom>' required here
    5 | constexpr bool is_convertible_v = __is_convertible(_From, _To);
      |                                                              ^
file.cpp:5:62: note: in instantiation of function template specialization 'tuple<ConvertibleFrom>::tuple<tuple<int>>' requested here
file.cpp:15:15: note: in instantiation of variable template specialization 'is_convertible_v<tuple<int>, tuple<ConvertibleFrom>>' requested here
   15 | static_assert(is_convertible_v<tuple<int>, tuple<ConvertibleFrom>>);
      |               ^
file.cpp:11:14: note: initializer of 'is_copy_constructible_v<tuple<int>>' is unknown
   11 |     requires is_copy_constructible_v<U0>
      |              ^
file.cpp:7:16: note: declared here
    7 | constexpr bool is_copy_constructible_v = __is_constructible(_Tp, _Tp);
      |                ^

Metadata

Metadata

Assignees

No one assigned

    Labels

    c++20clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerclang:frontendLanguage frontend issues, e.g. anything involving "Sema"conceptsC++20 concepts

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions