[Bug c++/70792] Incorrect sequence point warning with uniform initializer syntax

matthijsvanduin at gmail dot com gcc-bugzilla@gcc.gnu.org
Sun Sep 30 17:19:00 GMT 2018


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

Matthijs van Duin <matthijsvanduin at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |matthijsvanduin at gmail dot com

--- Comment #4 from Matthijs van Duin <matthijsvanduin at gmail dot com> ---
It seems bug 51253 previously addressed this, which means this is a regression.
Also bug 65866 exists for the warning itself.

I can confirm incorrect code generation using g++ 8.2.0 on this simpler
testcase:


#include <utility>

int main() {
        int i = -1;
        return std::pair{ ++i, ++i }.first;
}


$ g++ -Wall -std=c++17 -o list-init-sequence{,.cc}
list-init-sequence.cc: In function ‘int main()’:
list-init-sequence.cc:6:20: warning: operation on ‘i’ may be undefined
[-Wsequence-point]
  return std::pair{ ++i, ++i }.first;
                    ^~~
$ ./list-init-sequence || echo fail
fail


Interestingly, this variation does not produce a warning but still produces
incorrect code:

#include <utility>

int main() {
        int i = 0;
        return std::pair{ i, ++i }.first;
}

$ g++ -Wall -std=c++17 -o list-init-sequence{,.cc}
$ ./list-init-sequence || echo fail
fail


More information about the Gcc-bugs mailing list