0

I have the following snippet (I'm compiling for C++20):

struct Z {
    template <typename... Args>
    Z(std::vector<std::tuple<Args...>>) {}
};

Z z(std::vector{std::tuple{}});

g++-10 refuses to compile this with the error:

main.cpp:16:9: error: ‘auto’ parameter not permitted in this context
   16 |     Z z(std::vector{std::tuple{}});
      |         ^~~

However, clang++ version 10 successfully compiles it (and does the right thing if I create non-empty tuples and try printing their contents).

Is this a case of the most vexing parse? If so, how does clang++ manage to compile this? Otherwise, is this a bug with g++?

Svalorzen
  • 5,353
  • 3
  • 30
  • 54

1 Answers1

3

This is not the most vexing parse. The use of braces prevents the most vexing parse: for example, std::tuple{} cannot be interpreted as "function taking no arguments and returning std::tuple", while std::tuple() can. This means the latter can be part of a most vexing parse, while the former cannot.

This simply appears to be a bug in GCC, which is fixed in the "trunk" version currently on Godbolt: https://godbolt.org/z/Kds7hcr5f

Brian Bi
  • 111,498
  • 10
  • 176
  • 312