Reputation: 1
Following code compiles fine with g++ 4.4.5 but reports error with g++ 4.5.3 . Is it the compiler behavior that has changed. If so, what got changed?
#include <iostream>
using namespace std;
class A
{
public:
A() {}
};
int main()
{
new A::A();
return 0;
}
Upvotes: 0
Views: 378
Reputation: 1
Although class-name::class-name notation is defined as a constructor, It is not a type-id. The requirement of new specified in the [expr.new] definition in C++11 [5.3.1].
new-expression:
::optnew new-placementopt **new-type-id** new-initializeropt
::optnew new-placementopt( **type-id** ) new-initializeropt
Upvotes: 0
Reputation: 300019
Well, obviously the compiler behavior has changed, since you have an error where you had none before.
The thing is, calls to constructors should not be qualified (ie, preceded with a type). It seems that gcc 4.5.3 used to ignore the issue whilst 4.5.5 is stricter in its enforcement of the Standard.
EDIT:
I seem to remember this was forbidden (but everyone let it slide) in C++98. The C++11 Standard however explicitly accepts it, at least in certain places (see §5.5.1/8). It may well be that a bug was introduced when improving the support for C++11 in gcc or on the contrary that now it is only allowed in those places the C++11 Standard accepts; at the very least gcc 4.8.0 still rejects the code.
Strangely enough, Clang 3.2, which is generally strict, accepts the code without a warning.
Upvotes: 2