https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98841
--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jakub Jelinek <ja...@gcc.gnu.org>: https://gcc.gnu.org/g:850a8ec54c4310d779004299bf9a0dec52324e9e commit r11-6964-g850a8ec54c4310d779004299bf9a0dec52324e9e Author: Jakub Jelinek <ja...@redhat.com> Date: Fri Jan 29 00:39:00 2021 +0100 c++: Fix -Weffc++ in templates [PR98841] We emit a bogus warning on the following testcase, suggesting that the operator should return *this even when it does that already. The problem is that normally cp_build_indirect_ref_1 ensures that *this is folded as current_class_ref, but in templates (if return type is non-dependent, otherwise check_return_expr doesn't check it) it didn't go through cp_build_indirect_ref_1, but just built another INDIRECT_REF. Which means it then doesn't compare pointer-equal to current_class_ref. The following patch fixes it by doing in build_x_indirect_ref for *this what cp_build_indirect_ref_1 would do. 2021-01-28 Jakub Jelinek <ja...@redhat.com> PR c++/98841 * typeck.c (build_x_indirect_ref): For *this, return current_class_ref. * g++.dg/warn/effc5.C: New test.