This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/51253] [C++11][DR 1030] Evaluation order (sequenced-before relation) among initializer-clauses in braced-init-list


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51253

--- Comment #10 from Akim Demaille <akim.demaille at gmail dot com> ---
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... IS>
int f1()
{
  int i = 0;
  swallow{ i = 10 * i + IS... };
  return i;
}

fails, but

template<int... IS>
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 <iostream>
#include <tuple>

struct swallow
{
  template<typename... Types>
  swallow(Types &&...){}
};

int incr()
{
  static int res = 2;
  return res++;
}

template<int... IS>
int f1()
{
  int i = 0;
  swallow{ i = 10 * i + IS... };
  return i;
}

template<int... IS>
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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]