[Bug c++/95103] Unexpected -Wclobbered in bits/vector.tcc with -O2

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu May 14 10:22:56 GMT 2020


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

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The content of the warning isn't very helpful, but I think it's pointing out a
real issue in the code, not a false positive.

Any valid longjmp which followed that setjmp would have undefined behaviour if
executed, because 'v' has a non-trivial destructor.

The current wording is unclear, but CWG 2361 should clarify it, and LWG 1265
(closed as NAD) suggested different wording which would re-formulate the
function as:

void f3() try {
    std::vector<S> v;
    for (int i = 0; i != 2; ++i) {
        if (!f2("xx")) f1();
        v.push_back(0);
    }
    // ...
} catch (...) {
}

An exception thrown from the "..." part would cause the destruction of 'v' and
since that destructor is non-trivial, it would have undefined behaviour.


More information about the Gcc-bugs mailing list