From: Nathan Sidwell <nathan@acm.org>
To: GCC Patches <gcc-patches@gcc.gnu.org>
Cc: Jason Merrill <jason@redhat.com>
Subject: [c++] Implement DR 976
Date: Sat, 10 Jun 2023 17:28:42 -0400 [thread overview]
Message-ID: <4af0dc0a-b06b-372c-f2c3-e58b2141e027@acm.org> (raw)
[-- Attachment #1: Type: text/plain, Size: 397 bytes --]
DR 976 affects conversion operator deduction, swapping reference stripping and
cv-qual removal. This allows 'Y::operator P const & ()' to deduce T against a
call wanting plain A (previously that would fail as 'P const' cannot be deduced
from 'A').
It also affects deductions for array- or function-producing conversions, which I
suspect is rarer.
pushed to trunk
nathan
--
Nathan Sidwell
[-- Attachment #2: 0001-c-Adjust-conversion-deduction-PR61663-DR976.patch --]
[-- Type: text/x-patch, Size: 3195 bytes --]
From 80f075b410125bddb31459428760645baba1a69f Mon Sep 17 00:00:00 2001
From: Nathan Sidwell <nathan@acm.org>
Date: Sat, 10 Jun 2023 12:42:17 -0400
Subject: [PATCH] c++: Adjust conversion deduction [PR61663][DR976]
Drop the return type's reference before doing cvqual and related decays.
gcc/cp/
PR c++/61663
* pt.cc (maybe_adjust_types_for_deduction): Implement DR976.
gcc/testsuite/
* g++.dg/template/pr61663.C: New.
---
gcc/cp/pt.cc | 11 +++--
gcc/testsuite/g++.dg/template/pr61663.C | 63 +++++++++++++++++++++++++
2 files changed, 69 insertions(+), 5 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/template/pr61663.C
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 6b20c58ce66..6a2cf2c123f 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -22725,10 +22725,16 @@ maybe_adjust_types_for_deduction (tree tparms,
break;
case DEDUCE_CONV:
+ /* [temp.deduct.conv] First remove a reference type on parm.
+ DRs 322 & 976 affected this. */
+ if (TYPE_REF_P (*parm))
+ *parm = TREE_TYPE (*parm);
+
/* Swap PARM and ARG throughout the remainder of this
function; the handling is precisely symmetric since PARM
will initialize ARG rather than vice versa. */
std::swap (parm, arg);
+
break;
case DEDUCE_EXACT:
@@ -22795,11 +22801,6 @@ maybe_adjust_types_for_deduction (tree tparms,
result |= UNIFY_ALLOW_OUTER_MORE_CV_QUAL;
}
- /* DR 322. For conversion deduction, remove a reference type on parm
- too (which has been swapped into ARG). */
- if (strict == DEDUCE_CONV && TYPE_REF_P (*arg))
- *arg = TREE_TYPE (*arg);
-
return result;
}
diff --git a/gcc/testsuite/g++.dg/template/pr61663.C b/gcc/testsuite/g++.dg/template/pr61663.C
new file mode 100644
index 00000000000..2964fa6c309
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/pr61663.C
@@ -0,0 +1,63 @@
+// { dg-do compile { target c++11 } }
+// PR c++/61663
+// DR 976, strip ref from conv op return type before doing
+// fn and ary decay or CV qual removal
+
+struct F
+{
+ template<class T>
+ operator const T&();
+};
+
+void Foo ()
+{
+ F f;
+ int i = f;
+}
+
+template<typename T> struct X {};
+
+struct Y
+{
+ template<typename T> operator X<T> () &&; // #3
+ template<typename T> operator X<T> const & () const &; // #4
+};
+
+void Use (X<void>);
+Y Val ();
+Y const &Ref ();
+
+// { dg-final { scan-assembler "_Z5Frob3v:.*_ZNO1Ycv1XIT_EIvEEv.*_Z3Use1XIvE" } }
+void Frob3 ()
+{
+ Use (Val ()); // #3
+}
+
+// { dg-final { scan-assembler "_Z5Frob4v:.*_ZNKR1YcvRK1XIT_EIvEEv.*_Z3Use1XIvE" } }
+void Frob4 ()
+{
+ Use (Ref ()); // #4
+}
+
+struct Z
+{
+ template<typename T> using FnRef = void (&) (T);
+ template<typename T> using AryRef = T (&)[];
+
+ template<typename T> operator FnRef<T> ();
+ template<typename T> operator AryRef<T> ();
+};
+
+// { dg-final { scan-assembler "_Z5Frob5R1Z:.*_ZN1ZcvRFvT_EIiEEv.*_ZN1ZcvRA_T_IiEEv" } }
+void Frob5 (Z &z)
+{
+ void (*fnptr)(int) = z;
+ int *iptr = z;
+}
+
+// { dg-final { scan-assembler "_Z5Frob6R1Z:.*_ZN1ZcvRFvT_EIfEEv.*_ZN1ZcvRA_T_IfEEv" } }
+void Frob6 (Z &z)
+{
+ void (&fnref)(float) = z;
+ float (&aryref)[] = z;
+}
--
2.40.1
reply other threads:[~2023-06-10 21:28 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4af0dc0a-b06b-372c-f2c3-e58b2141e027@acm.org \
--to=nathan@acm.org \
--cc=gcc-patches@gcc.gnu.org \
--cc=jason@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).