Home Dashboard Directory Help
Search

Operator < incorrect for tuples with more members than _VARIADIC_MAX by Peter Gerell


Status: 

Closed
 as Fixed Help for as Fixed


1
0
Sign in
to vote
Type: Bug
ID: 742965
Opened: 5/21/2012 10:30:59 AM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
0
Workaround(s)
view
0
User(s) can reproduce this bug

Description

operator < for large tuples compiles but returns incorrect result.
Details
Sign in to post a comment.
Posted by Microsoft on 5/30/2012 at 4:14 PM
Hi,

Thanks for reporting this bug - such code shouldn't compile. We've already fixed it, and the fix will be available in VC11 RTM. This will fail to compile with:

C:\Temp>type meow.cpp
#include <iostream>
#include <ostream>
#include <tuple>
using namespace std;

typedef tuple<int, int, int, int, int, int> TupleType;

int main() {
    TupleType t1(1, 2, 3, 4, 5, 6);
    TupleType t2(2, 2, 3, 4, 5, 6);

    cout << (t1 < t2) << endl;
    cout << (t2 < t1) << endl;
}

C:\Temp>cl /EHsc /nologo /W4 /MTd meow.cpp
meow.cpp
meow.cpp(12) : error C2243: 'type cast' : conversion from 'TupleType *' to 'const std::tuple<<unnamed-symbol>,_V0_t,_V1_t,_V2_t,_V3_t,_V4_t> &' exists, but is inaccessible
        with
        [
            <unnamed-symbol>=int,
            _V0_t=int,
            _V1_t=int,
            _V2_t=int,
            _V3_t=int,
            _V4_t=std::_Nil
        ]
meow.cpp(13) : [...same...]

With _VARIADIC_MAX set to its default of 5, we define op<() for [0, 5]-tuples. Invoking it for 6-tuples used to compile because 6-tuples publicly derived from 5-tuples, so we sliced off the first element and compared the rest. Now that we've changed N+1-tuples to privately derive from N-tuples, this won't happen. (This is also responsible for the ugly, but technically accurate, compiler error here.)

There is an underlying problem here that has not been fixed: tuples larger than _VARIADIC_MAX shouldn't compile at all. That they do is an unintentional consequence of tuple having "too many" template arguments. (In our hideous macro scheme, it looks like tuple<_This, LIST(_TYPEX) COMMA PADDING_LIST(_NIL_PAD)>.) I had previously noticed this, but it was too tricky to attempt to untangle. In the future, this problem will be thoroughly fixed by real variadic templates. Until then, you should simply avoid creating tuples larger than _VARIADIC_MAX (you can increase it to 10 if necessary).

According to my understanding, tuple is the only thing which is affected by this problem (_VARIADIC_MAX not being a hard limit).

If you have any further questions, feel free to E-mail me at stl@microsoft.com .

Stephan T. Lavavej
Visual C++ Libraries Developer
Posted by MS-Moderator10 [Feedback Moderator] on 5/21/2012 at 8:49 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by MS-Moderator01 on 5/21/2012 at 10:43 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.