C++ compiler accepts explicit constructor call - by MB333

Status : 

  Deferred<br /><br />
		The product team has reviewed this issue and has deferred it for consideration at a later time.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.


3
0
Sign in
to vote
ID 783433 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 4/11/2013 4:59:55 AM
Access Restriction Public

Description

This code compiles but is invalid C++ (see section 12.1 - constructors do not have names)

class Thing
{
public:
    Thing() {}
};
 
Thing foo()
{
    // this line is not valid c++
    return Thing::Thing();
}
 
int main()
{
    foo();
}
Sign in to post a comment.
Posted by Ma3ztro on 10/28/2013 at 11:32 AM
Does this bug also applies to the following snippet?

class Foo
{
public:
    int m_value;
    Foo() : m_value(0) {}
};

Foo o;
o.Foo::Foo(); // Explicit constructor call!
Posted by UnitUniverse on 8/4/2013 at 6:15 PM
I spend some time to investigate it and find out the issue is not much important. What I'm worried about is the code like direct-calling through an object variable or a pointer to one. Watch out the code below:

// ConsoleApplication1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <Windows.h>


class C
{
public:
    C() {};
    ~C() { ::Beep(2400, 1000); };
};

void foo()
{
    {
        C::C();
    }
    {
        C o1;

        o1.C();// ***
    }
    return;
}

int _tmain(int argc, _TCHAR* argv[])
{
    foo();
    return 0;
}

The stars marked line will still yield C2274 error and terminate the further compiling process. And the line 'C::C();' is the same as defining a unnamed temporary rvalue object and get self-destroy immediately. So it won't cause any serious problem. the only thing you have to remember is better not write the code in such formal before or even after it has been solved by them.
Posted by UnitUniverse on 7/20/2013 at 1:44 PM
I think it's because the VC was extended for implementing Delegating Constructors, but the door to the side effects of not being closed yet.
Posted by Microsoft on 4/30/2013 at 4:56 AM
Hi MB333,

Thank you for taking the time to provide your feedback. After reviewing your reported issue, in the context of all the issues reported to us, we have decided not to take any action on this feedback at this time. We will re-consider our decision for a future release.

If this issue is severe, causing critical business situations or blocking your product development or deployment, please go to http://support.microsoft.com or call 1-800-MICROSOFT for assistance.
For Microsoft premier customers, please contact your administrator, your Technical Account Manager, or your Microsoft premier account representative.

Thanks,
Karl Niu
VC++ Team
Posted by Microsoft on 4/11/2013 at 7:45 PM
Thank you for submitting feedback on Visual Studio 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 Microsoft on 4/11/2013 at 5: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)