https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89780

--- Comment #9 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpola...@gcc.gnu.org>:

https://gcc.gnu.org/g:6602a2b2dee16af6e2d451c704789356042b5881

commit r13-2096-g6602a2b2dee16af6e2d451c704789356042b5881
Author: Marek Polacek <pola...@redhat.com>
Date:   Wed Aug 3 19:47:30 2022 -0400

    c++: Tweak for -Wpessimizing-move in templates [PR89780]

    In my previous patches I've been extending our std::move warnings,
    but this tweak actually dials it down a little bit.  As reported in
    bug 89780, it's questionable to warn about expressions in templates
    that were type-dependent, but aren't anymore because we're instantiating
    the template.  As in,

      template <typename T>
      Dest withMove() {
        T x;
        return std::move(x);
      }

      template Dest withMove<Dest>(); // #1
      template Dest withMove<Source>(); // #2

    Saying that the std::move is pessimizing for #1 is not incorrect, but
    it's not useful, because removing the std::move would then pessimize #2.
    So the user can't really win.  At the same time, disabling the warning
    just because we're in a template would be going too far, I still want to
    warn for

      template <typename>
      Dest withMove() {
        Dest x;
        return std::move(x);
      }

    because the std::move therein will be pessimizing for any instantiation.

    So I'm using the suppress_warning machinery to that effect.
    Problem: I had to add a new group to nowarn_spec_t, otherwise
    suppressing the -Wpessimizing-move warning would disable a whole bunch
    of other warnings, which we really don't want.

            PR c++/89780

    gcc/cp/ChangeLog:

            * pt.cc (tsubst_copy_and_build) <case CALL_EXPR>: Maybe suppress
            -Wpessimizing-move.
            * typeck.cc (maybe_warn_pessimizing_move): Don't issue warnings
            if they are suppressed.
            (check_return_expr): Disable -Wpessimizing-move when returning
            a dependent expression.

    gcc/ChangeLog:

            * diagnostic-spec.cc (nowarn_spec_t::nowarn_spec_t): Handle
            OPT_Wpessimizing_move and OPT_Wredundant_move.
            * diagnostic-spec.h (nowarn_spec_t): Add NW_REDUNDANT enumerator.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp0x/Wpessimizing-move3.C: Remove dg-warning.
            * g++.dg/cpp0x/Wredundant-move2.C: Likewise.

Reply via email to