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

Warwick Marangos <Warwick.Marangos at citadelsecurities dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |Warwick.Marangos@citadelsec
                   |                            |urities.com

--- Comment #5 from Warwick Marangos <Warwick.Marangos at citadelsecurities dot 
com> ---
(In reply to Andrew Pinski from comment #3)
> I would have thought this was by design. a statement expression last
> statement is "used" there.

The issue is perhaps more apparent in the following example:

$ cat example.cpp
#include <iostream>

struct [[nodiscard]] NoisyNodiscard {
    NoisyNodiscard() { std::cerr << "NoisyNodiscard()" << std::endl; }
    ~NoisyNodiscard() { std::cerr << "~NoisyNodiscard()" << std::endl; }
    NoisyNodiscard(NoisyNodiscard&&) { std::cerr <<
"NoisyNodiscard(NoisyNodiscard&&)" << std::endl; }
};

int main() {
    __extension__({
        NoisyNodiscard tmp;
        std::move(tmp);
    });

    return 0;
}

The final subexpression of the statement expression is an instance of
NoisyNodiscard&& and is used to construct the final value of the entire
statement expression, an instance of NoisyNodiscard. This final value is
immediately dropped. It certainly seems to me that this should qualify as going
unused.

Reply via email to