Pack expansion in mem-initializer-list with expression-list

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I am referring to C++14 standard [1] for the following problem.  I
already asked in [2] and got a comment that the following problem is a
GCC bug since Clang has no problem, and so I ask it here.

Section 12.6.2 "Initializing bases and members" paragraph 1 says that
mem-initializer can either be mem-initializer-id(expression-list_opt)
or mem-initializer-id braced-init-list, and mem-initializer... is a
valid construct. But, the following program shows otherwise:

#include <cstdio>

struct C1 {
  bool a;
  float b;
  C1(bool x, float y) : a(x), b(y) {}
};
struct C2 {
  bool c;
  float d;
  C2(bool x, float y) : c(x), d(y) {}
};
struct C3 {
  bool e;
  float f;
  C3(bool x, float y) : e(x), f(y) {}
};

template<class... baseclasses>
struct A : public baseclasses...
{
  template<class... Ts> A(Ts... args) : baseclasses(args...)... {
    // This uses mem-initializer-id(expression-list_opt).
    // Section 5.2 par 1 says that expression-list is initializer-list.
    // Section 8.5 par 1 says that initializer-list can be
    //     initializer-clause... with initializer-clause being
    //     assignment-expression.
    // Section 5.17 par 1 says that assignment-expression can boil down
    //     to an identifier, for example, args.
    // So, the construct is valid as far as I can see.  But,
    // g++ 5.4.1 fails with: invalid use of pack expansion expression.
    // g++ 7.2.0 fails with: no matching function for call to
    //     ‘C1::C1(bool)’.
    // The fix is to use mem-initializer-id braced-init-list as in:
    //     : baseclasses{args...}...
  }
};

int main() {
  A<C1, C2, C3> a(true, 1.0F);
  std::printf("%d %f %d %f %d %f\n", a.a, a.b, a.c, a.d, a.e, a.f);
}

My question is: is that a GCC bug?

If yes, I should file a GCC bugzilla report, shouldn't I?  Or,
somebody here is going to do that?

If not a GCC bug, where specifically in the C++14 standard is it
mentioned that parameter pack expansion in mem-initializer-list can
only work with the second alternative of mem-initializer? Or, is it
actually okay to use the first alternative but I need some syntax
trick to avoid ambiguity?

Thank you.

[1] http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3797.pdf
[2] https://stackoverflow.com/q/48849628

--
Best regards,
Tadeus




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux