[Bug c++/117615] [12/13/14/15 Regression] constexpr failure static_cast of Derived virtual Pointer to Member function since r6-4014-gdcdbc004d531b4
cvs-commit at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Thu Dec 5 08:59:00 GMT 2024
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117615
--- Comment #8 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Simon Martin
<simartin@gcc.gnu.org>:
https://gcc.gnu.org/g:ae8d9d2b40aa7fd6a455beda38ff1b3c21728c31
commit r12-10847-gae8d9d2b40aa7fd6a455beda38ff1b3c21728c31
Author: Simon Martin <simon@nasilyan.com>
Date: Tue Dec 3 14:30:43 2024 +0100
c++: Don't reject pointer to virtual method during constant evaluation
[PR117615]
We currently reject the following valid code:
=== cut here ===
struct Base {
virtual void doit (int v) const {}
};
struct Derived : Base {
void doit (int v) const {}
};
using fn_t = void (Base::*)(int) const;
struct Helper {
fn_t mFn;
constexpr Helper (auto && fn) : mFn(static_cast<fn_t>(fn)) {}
};
void foo () {
constexpr Helper h (&Derived::doit);
}
=== cut here ===
The problem is that since r6-4014-gdcdbc004d531b4, &Derived::doit is
represented with an expression with type pointer to method and using an
INTEGER_CST (here 1), and that cxx_eval_constant_expression rejects any
such expression with a non-null INTEGER_CST.
This patch uses the same strategy as r12-4491-gf45610a45236e9 (fix for
PR c++/102786), and simply lets such expressions go through.
PR c++/117615
gcc/cp/ChangeLog:
* constexpr.cc (cxx_eval_constant_expression): Don't reject
INTEGER_CSTs with type POINTER_TYPE to METHOD_TYPE.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/constexpr-virtual22.C: New test.
(cherry picked from commit 72a2380a306a1c3883cb7e4f99253522bc265af0)
More information about the Gcc-bugs
mailing list