vrrathod
vrrathod

Reputation: 1240

porting g++ code to Clang++ issue

Following code is a hypothetical code. This is a perfectly valid code under g++ (4.2.1). When compiled with Clang++ (4.2) it produces error as qualified reference to 'myclass' is a constructor name rather than a type wherever a constructor can be declared

class myclass
{
public:
    myclass() { }
    ~myclass() {}

};

myclass::myclass* funct() {
    return new myclass();
}

I could fix this by changing myclass::myclass* to myclass*. However I am not expected to change any code. Is there any commandline flags that I could provide in order to compile this code as is using Clang++ ?

Upvotes: 1

Views: 134

Answers (2)

quantdev
quantdev

Reputation: 23813

No, there is no such flag : since this program is ill-formed, it should not compile.

If a compiler compiles it, then it is a compiler bug. This bug report looks like the one impacting your particular gcc version.

The code should be fixed to :

myclass* funct() {
    return new myclass();
} 

Upvotes: 4

Philipp Claßen
Philipp Claßen

Reputation: 44019

gcc 4.9.1 also rejects the code:

 error: ‘myclass::myclass’ names the constructor, not the type

Unless the code base is happy with the rather old gcc 4.2, I see no alternative than to fix the code.

Upvotes: 3

Related Questions