Search

[C++] __alignof() fails to properly evalute alignment of dependent types by CodingCat

Closed
as Fixed Help for as Fixed

5
0
Sign in
to vote
Type: Bug
ID: 682695
Opened: 8/2/2011 11:15:28 AM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
0
Workaround(s)
0
User(s) can reproduce this bug
The VC++ 2010 compiler fails to properly evaluate the alignment of dependent types in template argument lists when these types have not been 'in use' before being passed to __alignof().

Always evaluating sizeof() with the types in question right before evaluating __alignof() works around this issue, yet, with the introduction of alignof to C++0x, this issue might become more relevant in the future.
Details (expand)

Visual Studio/Team Foundation Server/.NET Framework Tooling version

Visual Studio 2010 SP1

Steps to reproduce

#include <iostream>

template <class T>
struct foo
{
    T value;
};

template <class T, size_t A = __alignof(foo<T>)>
struct foo_alignment
{
    static const size_t value = A;
};

struct fwd_decl;

int main()
{
    // SIDE NOTE: Adding this sizeof evaluation before using foo_alignment works around the issue
//    sizeof(foo<int>);

    // ERROR: prints 0, should be 4
    std::cout << foo_alignment<int>::value << std::endl;

    // SIDE NOTE: prints 0, but should rather fail just like sizeof(fwd_decl) would?
    std::cout << __alignof(fwd_decl) << std::endl;

    return 0;
}

Product Language

English

Operating System

Windows Vista

Operating System Language

German

Actual results

foo_alignment<int>::value evaluates to 0

Expected results

foo_alignment<int>::value should be 4
File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 9/6/2011 at 12:39 PM
Hi: this issue has been fixed. The fix should show up in a future release of Visual C++.

Thank you for reporting the issue.

Jonathan Caves
Visual C++ Compiler Team
Posted by MS-Moderator08 [Feedback Moderator] on 8/2/2011 at 7:38 PM
Thank you for submitting feedback on Visual Studio 2010 and .NET Framework. Your issue has been routed to the appropriate VS development team for investigation. We will contact you if we require any additional information.
Posted by MS-Moderator01 on 8/2/2011 at 11:50 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.