From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24138 invoked by alias); 10 Apr 2014 08:14:42 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 24078 invoked by uid 48); 10 Apr 2014 08:14:37 -0000 From: "akim.demaille at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/51253] [C++11][DR 1030] Evaluation order (sequenced-before relation) among initializer-clauses in braced-init-list Date: Thu, 10 Apr 2014 08:14:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 4.7.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: akim.demaille at gmail dot com X-Bugzilla-Status: NEW X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-04/txt/msg00708.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51253 --- Comment #10 from Akim Demaille --- Well, I have finally found a simple workaround for some of the cases: GCC seems to be right in the order of evaluation when initializing an array so: template int f1() { int i = 0; swallow{ i = 10 * i + IS... }; return i; } fails, but template int f2() { using swallow = int[]; int i = 0; (void) swallow{ i = 10 * i + IS... }; return i; } succeeds. However, GCC's own libstdc++ is exposed to this bug, for instance make_tuple. $ cat foo.cc #include #include struct swallow { template swallow(Types &&...){} }; int incr() { static int res = 2; return res++; } template int f1() { int i = 0; swallow{ i = 10 * i + IS... }; return i; } template int f2() { using swallow = int[]; int i = 0; (void) swallow{ i = 10 * i + IS... }; return i; } int main() { // `i = i * 2 + 2' should be sequenced before `i = i * 3 + 3' std::cerr << f1<2, 3>() << '\t'; std::cerr << f2<2, 3>() << '\t'; auto t = std::make_tuple(incr(), incr()); std::cerr << std::get<0>(t) << std::get<1>(t) << '\n'; } $ ./a.32 23 23 23 $ ./a.33 23 23 23 $ ./a.34 23 23 23 $ ./a.35 23 23 23 $ ./a.48 32 23 32 $ ./a.49 32 23 32 where 32...35 is clang++, and 48,49 is gcc.