From dbf717037ba28223bb7910f999bded71d11538e1 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 13 Feb 2018 22:40:35 +0100 Subject: [PATCH] re PR c++/84364 (-Weffc++ warns on "return *this" in template after r253599) 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 | 7 +++++++ gcc/cp/typeck.c | 3 ++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/warn/effc4.C | 10 ++++++++++ 4 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/warn/effc4.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 84fb9094d90..ed44d9e2842 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2018-02-13 Jakub Jelinek + + 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 PR c++/84333 diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index dfcf71689c6..0e7c63dd197 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -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; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f22c21afb76..04d5fd479c7 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-02-13 Jakub Jelinek + + PR c++/84364 + * g++.dg/warn/effc4.C: New test. + 2018-02-13 Paolo Carlini 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 index 00000000000..2ce79280104 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/effc4.C @@ -0,0 +1,10 @@ +// PR c++/84364 +// { dg-do compile } +// { dg-options "-Weffc++" } + +template +struct A { + A &operator=(A& f) { + return *this; // { dg-bogus "should return a reference to" } + } +}; -- 2.30.2