re PR c++/84364 (-Weffc++ warns on "return *this" in template after r253599)
authorJakub Jelinek <jakub@redhat.com>
Tue, 13 Feb 2018 21:40:35 +0000 (22:40 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 13 Feb 2018 21:40:35 +0000 (22:40 +0100)
PR c++/84364
* typeck.c (check_return_expr): Don't emit -Weffc++ warning
about return other than *this in assignment operators if
retval is type dependent expression.

* g++.dg/warn/effc4.C: New test.

From-SVN: r257640

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

index 84fb9094d908d32c594376da73efb48fe29e8acd..ed44d9e28426796a8c2a78420f5b03a1d758e8ad 100644 (file)
@@ -1,3 +1,10 @@
+2018-02-13  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/84364
+       * typeck.c (check_return_expr): Don't emit -Weffc++ warning
+       about return other than *this in assignment operators if
+       retval is type dependent expression.
+
 2018-02-13  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/84333
index dfcf71689c63aee2494735f1e2b38f04db08e3cc..0e7c63dd197354fe07c9ca0b86fd05c20ae10ac2 100644 (file)
@@ -9232,7 +9232,8 @@ check_return_expr (tree retval, bool *no_warning)
 
   /* Effective C++ rule 15.  See also start_function.  */
   if (warn_ecpp
-      && DECL_NAME (current_function_decl) == assign_op_identifier)
+      && DECL_NAME (current_function_decl) == assign_op_identifier
+      && !type_dependent_expression_p (retval))
     {
       bool warn = true;
 
index f22c21afb76b4410e21a078b6911f6123102019a..04d5fd479c7855640774efa54fab214c43a35b19 100644 (file)
@@ -1,3 +1,8 @@
+2018-02-13  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/84364
+       * g++.dg/warn/effc4.C: New test.
+
 2018-02-13  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/84333
diff --git a/gcc/testsuite/g++.dg/warn/effc4.C b/gcc/testsuite/g++.dg/warn/effc4.C
new file mode 100644 (file)
index 0000000..2ce7928
--- /dev/null
@@ -0,0 +1,10 @@
+// PR c++/84364
+// { dg-do compile }
+// { dg-options "-Weffc++" }
+
+template <typename T>
+struct A {
+  A &operator=(A<T>& f) {
+    return *this;      // { dg-bogus "should return a reference to" }
+  }
+};