Search code examples
c++g++clang++llvm-clang

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++ ?


Solution

  • 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();
    }