5

I just came across a very strange situation when writing a C++11 std::tuple-like class and trying to compile it with g++-4.7. What I basically need is a tuple of wrapped types. I wrote something like this:

#include <tuple> 

template <class T> 
struct Wrapper { T x; }; 

template <class... Types> 
using Tuple = std::tuple<Wrapper<Types>...>; 

template <class... Types> 
struct X 
{ 
    using MyTuple = Tuple<Types...>; 
}; 

int main( int argc, char** argv ) 
{ 
    // Tuple<int,int> t;  // (1)
    using Y = X<int,int>;
    Y y;                  // (2)
    return 0; 
}

I made the following observations:

  1. The code does not compile:
  2. If I add (1), it does compile.
  3. If I remove (1) and (2), it does compile as well.

Error message for 1.:

test.cpp: In instantiation of ‘struct X<int, int>’:
test.cpp:22:4:   required from here
test.cpp:10:44: error: wrong number of template arguments (2, should be 1)
test.cpp:4:8: error: provided for ‘template<class T> struct Wrapper’

Question: In my opinion the code above is correct, but it is the first time that I actually use parameter packs. Are there any reasons that g++-4.7 does not like my code except for the fact that it is an experimental implementation?

3
  • 2
    The code you provided compiles just fine, and from the error it seems that you accidentally wrote std::tuple<Wrapper<Types...>> instead of std::tuple<Wrapper<Types>...>. Please provide the real code and try it again before posting.
    – Xeo
    May 28, 2013 at 7:24
  • 1
    Compiles in GCC 4.8. May 28, 2013 at 7:27
  • This is the real code. I thought that I made the error that you describe, but in fact I did not. May 28, 2013 at 7:28

1 Answer 1

3

This is most likely a bug in g++ 4.7 that is fixed in g++ 4.8. Ideone (which uses g++ 4.7.2, and which I cannot link to without duplicating your code example, argh) gives the error you mention, whereas Coliru (using g++ 4.8) compiles without error.

7
  • It's not Stacked-Crooked. It's Coliru. Though it is Stack-Croocked's. May 28, 2013 at 7:46
  • it's called Stacked-Crooked on isocpp.org/get-started, not that it matters May 28, 2013 at 7:47
  • I can confirm that GCC 4.7.2 gives the error, while GCC 4.8 and 4.9 snapshot do not. But the specific bug you link to says "fixed for 4.7.1"..?
    – jogojapan
    May 28, 2013 at 7:48
  • @rhalbersma: It didn't have a name when it was added there, so they likely just took the address - but the creator of it (StackedCrooked) named it "Coliru", and that's also what's displayed at the top when in edit mode. :)
    – Xeo
    May 28, 2013 at 7:51
  • @jogojapan the bug I linked had the same error message and samme language feature, but occurred in a different context than this question. Just speculating, but it could have the same underlying defect, that was partially fixed in 4.7.1 and more fully in 4.8. I can't locate the same bug for 4.7.2, though. May 28, 2013 at 8:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.