]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: Fix reference NTTP binding to noexcept fn [PR97420]
authorPatrick Palka <ppalka@redhat.com>
Wed, 26 May 2021 12:35:31 +0000 (08:35 -0400)
committerPatrick Palka <ppalka@redhat.com>
Wed, 26 May 2021 12:35:31 +0000 (08:35 -0400)
commitb4329e3dd6fb7c78948fcf9d2f5b9d873deec284
treed00562e26db85a44f3d94e1eee696e92b47d3c63
parent95d67762171f83277a5700b270c0d1e2756f83f4
c++: Fix reference NTTP binding to noexcept fn [PR97420]

Here, in C++17 mode, convert_nontype_argument_function is rejecting
binding a non-noexcept function reference template parameter to a
noexcept function (encoded as the template argument '*(int (&) (int)) &f').

The first roadblock to making this work is that the argument is wrapped
an an implicit INDIRECT_REF, so we need to unwrap it before calling
strip_fnptr_conv.

The second roadblock is that the NOP_EXPR cast converts from a function
pointer type to a reference type while simultaneously removing the
noexcept qualification, and fnptr_conv_p doesn't consider this cast to
be a function pointer conversion.  This patch fixes this by making
fnptr_conv_p treat REFERENCE_TYPEs and POINTER_TYPEs interchangeably.

Finally, in passing, this patch also simplifies noexcept_conv_p by
removing a bunch of redundant checks already performed by its only
caller fnptr_conv_p.

PR c++/97420

gcc/cp/ChangeLog:

* cvt.c (noexcept_conv_p): Remove redundant checks and simplify.
(fnptr_conv_p): Don't call non_reference.  Use INDIRECT_TYPE_P
instead of TYPE_PTR_P.
* pt.c (convert_nontype_argument_function): Look through
implicit INDIRECT_REFs before calling strip_fnptr_conv.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/noexcept68.C: New test.
gcc/cp/cvt.c
gcc/cp/pt.c
gcc/testsuite/g++.dg/cpp0x/noexcept68.C [new file with mode: 0644]