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

            Bug ID: 102249
           Summary: Can't compare pointer to functions during constant
                    evaluation
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: johelegp at gmail dot com
                CC: johelegp at gmail dot com
  Target Milestone: ---

This is specified at https://eel.is/c++draft/expr.eq#3. See
https://godbolt.org/z/Wdradsb4a.
```C++
#include <functional>
static_assert(not std::ranges::equal_to{}([]{}, +[]{}));
static_assert(std::not_equal_to{}([]{}, +[]{}));
static_assert([]{} != +[]{});
```
```
<source>:2:15: error: non-constant condition for static assertion
    2 | static_assert(not std::ranges::equal_to{}(+[]{}, +[]{}));
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/iterator_concepts.h:37,
                 from
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/stl_iterator_base_types.h:71,
                 from
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/stl_algobase.h:65,
                 from
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/array:40,
                 from
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/tuple:39,
                 from
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/functional:54,
                 from <source>:1:
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/ranges_cmp.h:93:39:
error: '(<lambda()>::_FUN == <lambda()>::_FUN)' is not a constant expression
   93 |       { return std::forward<_Tp>(__t) == std::forward<_Up>(__u); }
      |                ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
<source>:3:34: error: non-constant condition for static assertion
    3 | static_assert(std::not_equal_to{}(+[]{}, +[]{}));
      |               ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
In file included from
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/functional:49,
                 from <source>:1:
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/bits/stl_function.h:509:41:
error: '(<lambda()>::_FUN != <lambda()>::_FUN)' is not a constant expression
  509 |         { return std::forward<_Tp>(__t) != std::forward<_Up>(__u); }
      |                  ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
<source>:4:21: error: non-constant condition for static assertion
    4 | static_assert(+[]{} != +[]{});
<source>:4:21: error: '(<lambda()>::_FUN != <lambda()>::_FUN)' is not a
constant expression
Compiler returned: 1
```

Reply via email to