Home Dashboard Directory Help

Calling decltype(*this) crashes the compiler with C1001 by Matt Olenik



Sign in
to vote
Type: Bug
ID: 535785
Opened: 2/23/2010 6:52:09 PM
Access Restriction: Public
Primary Feedback Item: 535484
User(s) can reproduce this bug


If you have a class Foo, and try to use decltype(*this) somewhere in a method (or constructor) of that class, the compiler crashes with C1001. Example:

class Foo
    void bar()
        decltype(*this) x();    // C1001
        decltype(*this) x;     // C1001

I am uncertain if this is valid C++, although I don't see why it wouldn't be. In any case, if it is invalid, it should report an appropriate error message rather than crash.

Also note that this only occurs on the this pointer, with any other pointer the decltype call works as expected.
Sign in to post a comment.
Posted by Microsoft on 2/24/2010 at 8:23 AM
Hi: I can confirm that this is a bug with Visual C++. Unfortunately it does not meet the triage bar for the current release of Visual C++ - but we will keep the issue in our database and we will look at it again during the development phase of a future release of Visual C++.

Jonathan Caves
Visual C++ Compiler Team
Posted by Microsoft on 2/23/2010 at 7:07 PM
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.
Posted by Viorel_ on 4/20/2010 at 6:11 AM
As a workaround try this:

    decltype(this[0]) x;

Note that as IntelliSense suggests, this construct, as well as ‘decltype(*this)’, denotes a reference which has to be initialized. If you actually want to create a local variable of structure type, then consider this:

    decltype(*this, *this) x;