This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/61382] parameter pack expansion unexpected order
- From: "thibaut.lutz at googlemail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 03 Jun 2014 23:03:38 +0000
- Subject: [Bug c++/61382] parameter pack expansion unexpected order
- Auto-submitted: auto-generated
- References: <bug-61382-4 at http dot gcc dot gnu dot 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 unspeciïed.
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.