re PR c++/49812 (strange return type for built-in operator++(int, int))
authorJason Merrill <jason@redhat.com>
Fri, 5 Aug 2011 19:12:24 +0000 (15:12 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 5 Aug 2011 19:12:24 +0000 (15:12 -0400)
PR c++/49812
* typeck.c (cp_build_unary_op) [POSTINCREMENT_EXPR]: Strip cv-quals.

From-SVN: r177479

gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/overload/rvalue2.C [new file with mode: 0644]

index d7ad9929c931a048f71a6eea7ab4b5fc4282d4f1..46eee7e8dbd8382fbcd11f253326260a09e40d85 100644 (file)
@@ -1,5 +1,8 @@
 2011-08-05  Jason Merrill  <jason@redhat.com>
 
+       PR c++/49812
+       * typeck.c (cp_build_unary_op) [POSTINCREMENT_EXPR]: Strip cv-quals.
+
        PR c++/49983
        * parser.c (cp_parser_range_for): Only do auto deduction in
        template if the range is non-dependent.
index ab08eae28590aae9b063b99a13dd771646fa12b6..f53deb985a62386b40087f1f762fa190dfdc29fd 100644 (file)
@@ -5220,6 +5220,9 @@ cp_build_unary_op (enum tree_code code, tree xarg, int noconvert,
              }
            val = boolean_increment (code, arg);
          }
+       else if (code == POSTINCREMENT_EXPR || code == POSTDECREMENT_EXPR)
+         /* An rvalue has no cv-qualifiers.  */
+         val = build2 (code, cv_unqualified (TREE_TYPE (arg)), arg, inc);
        else
          val = build2 (code, TREE_TYPE (arg), arg, inc);
 
index 4956e57e77737fa84b80caa21e591c2012674858..6ba618327bedcdc420e93dbc55857e7e208ab42f 100644 (file)
@@ -1,5 +1,8 @@
 2011-08-05  Jason Merrill  <jason@redhat.com>
 
+       PR c++/49812
+       * g++.dg/overload/rvalue2.C: New.
+
        PR c++/49983
        * g++.dg/cpp0x/range-for21.C: New.
 
diff --git a/gcc/testsuite/g++.dg/overload/rvalue2.C b/gcc/testsuite/g++.dg/overload/rvalue2.C
new file mode 100644 (file)
index 0000000..8a2290d
--- /dev/null
@@ -0,0 +1,11 @@
+// PR c++/49812
+// The call should choose the second f because i++ is an int rvalue.
+
+template <class T> void f(const volatile T& t) { t.i; }
+template <class T> void f(const T&);
+
+int main()
+{
+  volatile int i = 0;
+  f(i++);
+}