Now that convert_like creates an IMPLICIT_CONV_EXPR when it converts
something that involves a class in a template, we must be prepared to
handle it.  In this test, we have a class S and we're converting it
to long int& using a user-defined conversion since we're performing
-- on it.  So cp_build_unary_op/POSTDECREMENT_EXPR calls
build_expr_type_conversion which gets the IMPLICIT_CONV_EXPR.  Before
the convert_like change it got *S::operator long int &(&b) whose type
is long int but now it gets IMPLICIT_CONV_EXPR<long int&>(b) whose type
is a reference type.  But the !MAYBE_CLASS_TYPE_P switch doesn't handle
reference types and so we complain.  Thus, use non_reference, which is
used in the function when looking for the best conversion candidate.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

        PR c++/94190 - wrong no post-decrement operator error in template.
        * cvt.c (build_expr_type_conversion): Use non_reference.

        * g++.dg/conversion/op7.C: New test.
---
 gcc/cp/cvt.c                          |  2 +-
 gcc/testsuite/g++.dg/conversion/op7.C | 22 ++++++++++++++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/conversion/op7.C

diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c
index 22a72c08c45..0c285ed4fe9 100644
--- a/gcc/cp/cvt.c
+++ b/gcc/cp/cvt.c
@@ -1732,7 +1732,7 @@ build_type_conversion (tree xtype, tree expr)
 tree
 build_expr_type_conversion (int desires, tree expr, bool complain)
 {
-  tree basetype = TREE_TYPE (expr);
+  tree basetype = non_reference (TREE_TYPE (expr));
   tree conv = NULL_TREE;
   tree winner = NULL_TREE;
 
diff --git a/gcc/testsuite/g++.dg/conversion/op7.C 
b/gcc/testsuite/g++.dg/conversion/op7.C
new file mode 100644
index 00000000000..c6401d109b4
--- /dev/null
+++ b/gcc/testsuite/g++.dg/conversion/op7.C
@@ -0,0 +1,22 @@
+// PR c++/94190 - wrong no post-decrement operator error in template.
+
+struct S { operator long & (); } b;
+
+template<int> void
+foo ()
+{
+  b--;
+  ++b;
+  --b;
+  b++;
+  !b;
+  ~b;
+  +b;
+  -b;
+}
+
+void
+bar ()
+{
+  foo<0> ();
+}

base-commit: 5a3c42b227bbe9e7acb5335088d2255262311bd8
-- 
Marek Polacek • Red Hat, Inc. • 300 A St, Boston, MA

Reply via email to