Home Dashboard Directory Help
Search

Buggy static_assert by Knowing me knowing you, a-ha


Status: 

Closed
 as Fixed Help for as Fixed


1
0
Sign in
to vote
Type: Bug
ID: 657040
Opened: 4/2/2011 7:49:03 AM
Access Restriction: Public
0
Workaround(s)
view
0
User(s) can reproduce this bug

Description

This should compile:
template<class T>
struct Assign_Low_High
{
    static const int low_value = 0;
};
//in order to compile remove "class IntType," from template<class IntType, class L>
template<class IntType, class L>
struct Range
{
    static_assert(Assign_Low_High<L>::low_value < 1, "Incorrect Range");
};

int main()
{
//in order to compile remove "int," from Range<int,float>
Range<int,float> r;
    return 0;
}
Interesting thing here is that it will compile if you remove "class IntType," from struct Range template definition
Details
Sign in to post a comment.
Posted by Microsoft on 1/24/2012 at 12:03 PM
Hi:
    After working with VS / Windows / SQL team, we finally fixed all related code defects in our codebase. So the fix for this issue is checked into the compiler sources now. The fix should show up in the next release of Visual C++.

Xiang Fan
Visual C++ Team
Posted by Microsoft on 6/7/2011 at 5:58 PM
Hi,
    The issue you saw is related to static_assert, but the root cuase is what I mentioned in the previous response:

    The compiler doesn't fully implement "template" restriction on argument dependent name and it always prefers the identifier as template.

    For example, our compiler incorrectly accepts the following code:

template<int> struct C0 {
};

template<class T> struct C1 {
    template<class U> struct C {enum {n = 0};};
};
template<class T> struct C2 {int value;};

template<class U, class T>
struct Range
{
    // works in VC (in fact, it requires "template" keyword)
    const static int i = C1<U>::C<int>::n;
};
Posted by Knowing me knowing you, a-ha on 5/26/2011 at 11:16 AM
Excuse me, would you mind explaining to me how legacy code be affected? What I understand by legacy code is a code written some time ago which used such feature and changing this feature it the way it works would breake this aforementioned legacy code.
But here we talking about static_assert, and as far as I'm concerned it is brand new feature from C++11 so how fixing this and making to work correctly would possibly break any legacy code?
Looking forward to your reply.
Posted by Microsoft on 5/25/2011 at 11:10 PM
Hi,
    Thanks for reporting the issue.
    I can confirm that this is a bug in the compiler. The compiler doesn't fully implement "template" restriction on argument dependent name and it always prefers the identifier as template.
    Unfortunately, the fix is a breaking change and will break legacy code. Because there is an easy workaround, we decide not to fix it in this release. We will though keep the bug in our database and we will look at it for a future release of Visual C++.

    BTW, the removal of "IntType" works by coincidence.

Xiang Fan
Visual C++ Team
Posted by Knowing me knowing you, a-ha on 4/9/2011 at 8:06 AM
Thanks too. I'm always happy to help.
Regards
Artur
Posted by Microsoft on 4/8/2011 at 4:17 PM
Doing some more poking around, the bug is with our parser and static_assert keyword. And that < binary operator is messing things up. If you put parens around the expression to the typetrait, then compiler can parse it right. It's just a workaround till we get our acts together. Thanks a lot for the bug, appreciate it.

    static_assert((Assign_Low_High<L>::low_value) < 1, "Incorrect Range");

Thanks,
Ulzii Luvsanbat
Windows C++ Team
Posted by Microsoft on 4/8/2011 at 3:43 PM
Hi,

Thanks for reporting this bug. This indeed is a pretty bad bug, I'm surprised we missed this, we apologize. We're fixing it.

Thanks,
Ulzii Luvsanbat
Windows C++ Team
Posted by Microsoft on 4/3/2011 at 6:17 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 Microsoft on 4/3/2011 at 6:17 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 Microsoft on 4/2/2011 at 8:14 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.