public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "thibaut.lutz at googlemail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/61382] parameter pack expansion  unexpected order
Date: Tue, 03 Jun 2014 23:03:00 -0000	[thread overview]
Message-ID: <bug-61382-4-RNTKh1BAVR@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-61382-4@http.gcc.gnu.org/bugzilla/>

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

Thibaut LUTZ <thibaut.lutz at googlemail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |thibaut.lutz at googlemail dot com

--- Comment #2 from Thibaut LUTZ <thibaut.lutz at googlemail dot com> ---
@Jonathan: you might be referring to 56774. 59716 was a similar issue.

However I think this case is definitely NOT a bug. Here is why:

- let's decompose the line:
std::tuple<ARGS...> r { get_single<ARGS>(posfoo++)... };

* std::tuple<ARGS...> r{ ... }: this is a constructor call: std::tuple(args...)
* get_single<ARGS>(posfoo++)... expands to get_single<int>(posfoo++),
get_single<float>(posfoo++), get_single<float>(posfoo++),
get_single<int>(posfoo++)

Putting the two together, with the previous line:
int posfoo = 0;
std::tuple<ARGS...> r ( get_single<int>(posfoo++),
                        get_single<float>(posfoo++),
                        get_single<float>(posfoo++),
                        get_single<int>(posfoo++));

This is the root of your problem: 
N3797 §8.3.6.9: The order of evaluation of function arguments is unspecified.

The pack expansion is working fine, but the increments to posfoo are not being
sequenced. Clang does evaluate arguments in the opposite order as GCC does,
which makes it look correct in this case, but it is still undefined behavior. 

You can re-write your get_single function to do a pack traversal instead.
>From gcc-bugs-return-453145-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Wed Jun 04 01:06:19 2014
Return-Path: <gcc-bugs-return-453145-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 9251 invoked by alias); 4 Jun 2014 01:06:19 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 9208 invoked by uid 48); 4 Jun 2014 01:06:15 -0000
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/61382] parameter pack expansion  unexpected order
Date: Wed, 04 Jun 2014 01:06: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.9.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: redi at gcc dot gnu.org
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-61382-4-z9LGwYv9kd@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-61382-4@http.gcc.gnu.org/bugzilla/>
References: <bug-61382-4@http.gcc.gnu.org/bugzilla/>
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-06/txt/msg00227.txt.bz2
Content-length: 653

https://gcc.gnu.org/bugzilla/show_bug.cgi?ida382

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Thibaut LUTZ from comment #2)
> @Jonathan: you might be referring to 56774. 59716 was a similar issue.

They don't look related. I meant PR 51253

> However I think this case is definitely NOT a bug. Here is why:
>
> - let's decompose the line:
> std::tuple<ARGS...> r { get_single<ARGS>(posfoo++)... };
>
> * std::tuple<ARGS...> r{ ... }: this is a constructor call:
> std::tuple(args...)

No, this is not a valid transformation, the semantics of T r{args...} are not
the same as T r(args...), see [dcl.init.list] p4.


  parent reply	other threads:[~2014-06-03 23:03 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-01 21:17 [Bug c++/61382] New: " pengujohn at xvlc dot de
2014-06-01 22:27 ` [Bug c++/61382] " redi at gcc dot gnu.org
2014-06-03 23:03 ` thibaut.lutz at googlemail dot com [this message]
2014-06-04  8:50 ` thibaut.lutz at googlemail dot com
2014-06-04 15:51 ` jason at gcc dot gnu.org
2014-06-04 15:52 ` jason at gcc dot gnu.org
2014-06-11 21:35 ` pengujohn at xvlc dot de
2014-06-30 14:26 ` jason at gcc dot gnu.org
2014-07-03  2:02 ` brooks at gcc dot gnu.org
2014-07-03  3:37 ` brooks at gcc dot gnu.org
2014-07-03  8:29 ` jakub at gcc dot gnu.org
2014-07-04  7:24 ` jason at gcc dot gnu.org
2014-07-04  8:24 ` jakub at gcc dot gnu.org
2014-07-08  2:57 ` brooks at gcc dot gnu.org
2014-07-08 22:34 ` jason at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-61382-4-RNTKh1BAVR@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).