https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126188

            Bug ID: 126188
           Summary: [reflection] can_substutite triggers static_assert
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gcc at hazardy dot de
  Target Milestone: ---

Given

#include <meta>
#include <type_traits>
#include <concepts>

auto l = [](auto x) {
    static_assert(std::same_as<std::decay_t<decltype(x)>, int>);
};

constexpr bool canInt = std::meta::can_substitute(^^decltype(l)::operator(),
{^^int});
constexpr bool canDouble = std::meta::can_substitute(^^decltype(l)::operator(),
{^^double});

I get (with current trunk on godbolt):
<source>: In instantiation of '<lambda(auto:6)> [with auto:6 = double]':
<source>:10:53:   required from here
   10 | constexpr bool canDouble =
std::meta::can_substitute(^^decltype(l)::operator(), {^^double});
      |                           
~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:6:24: error: static assertion failed
    6 |     static_assert(std::same_as<std::decay_t<decltype(x)>, int>);
      |                   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • constraints not satisfied
In file included from
/cefs/e2/e2c410130d426afdae2fdae5_gcc-trunk-20260709/include/c++/17.0.0/compare:44,
                 from
/cefs/e2/e2c410130d426afdae2fdae5_gcc-trunk-20260709/include/c++/17.0.0/array:40,
                 from
/cefs/e2/e2c410130d426afdae2fdae5_gcc-trunk-20260709/include/c++/17.0.0/meta:42,
                 from <source>:1:
    • required for the satisfaction of '__same_as<_Tp, _Up>' [with _Tp =
double; _Up = int]
     
/cefs/e2/e2c410130d426afdae2fdae5_gcc-trunk-20260709/include/c++/17.0.0/concepts:59:15:
 
         59 |       concept __same_as = std::is_same_v<_Tp, _Up>;
            |               ^~~~~~~~~
    • the expression 'is_same_v<_Tp, _Up> [with _Tp = double; _Up = int]'
evaluated to 'false'
     
/cefs/e2/e2c410130d426afdae2fdae5_gcc-trunk-20260709/include/c++/17.0.0/concepts:59:32:
         59 |       concept __same_as = std::is_same_v<_Tp, _Up>;
            |                           ~~~~~^~~~~~~~~~~~~~~~~~~
    • 'double' is not the same as 'int'


It doesn't get triggered with GCC 16.1, but there both bools are true.
Locally I have 16.1 with 7555c9b1c86b72049049fdde1c987cc7a6505fb0 and
e1396e44961be4856cdd91782d73b45014a4b276 cherry picked and that shows the same
behavior.

Other compile errors, like using non existent members of T also trigger.

Reply via email to