[Bug c++/100313] pointer to member function is not const with sanitize=undefined

3440910457 at qq dot com via Gcc-bugs <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100313

--- Comment #5 from 3440910457 at qq dot com ---
This bug can be triggered not only by pointer member function, but also by
pointers to inline free functions, for example:

See <https://godbolt.org/z/enznGjczv>

```
#include <functional>

// inline is necessary
inline int add(int a, int b) { return a + b; }

int main() {
    constexpr auto f = std::function_ref(std::cw<&add>);
}
```

The full error is:

In file included from
/cefs/d7/d7b08a093b417e580f5102b8_gcc-trunk-20260810/include/c++/17.0.0/bits/funcwrap.h:667,
                 from
/cefs/d7/d7b08a093b417e580f5102b8_gcc-trunk-20260810/include/c++/17.0.0/functional:93,
                 from <source>:1:
/cefs/d7/d7b08a093b417e580f5102b8_gcc-trunk-20260810/include/c++/17.0.0/bits/funcref_impl.h:
In instantiation of 'constexpr std::function_ref<_Res(_ArgTypes ...) noexcept
(_Noex)>::function_ref(std::constant_wrapper<__fn, _Fn>) [with auto __fn = add;
_Fn = int (*)(int, int); _Res = int; _ArgTypes = {int, int}; bool _Noex =
false]':
<source>:7:55:   required from here
    7 |     constexpr auto f = std::function_ref(std::cw<&add>);
      |                                                       ^
/cefs/d7/d7b08a093b417e580f5102b8_gcc-trunk-20260810/include/c++/17.0.0/bits/funcref_impl.h:148:32:
error: non-constant condition for static assertion
  148 |             static_assert(__fn != nullptr);
      |                           ~~~~~^~~~~~~~~~
/cefs/d7/d7b08a093b417e580f5102b8_gcc-trunk-20260810/include/c++/17.0.0/bits/funcref_impl.h:148:32:
error: '(add != 0)' is not a constant expression
Compiler returned: 1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.