0

The assertion in the following program gives different results according to the compiler used: in GCC 4.4 the assertions fails, while in CLang does not. It looks like GCC does not like V being private in C. Is this a bug?

#include <cassert>

class V {
public:
    virtual ~V() { };
};

template<class T>
class C : public T, private V {
public:
    static V* new_() {
        return new C();
    }
};

struct MyT {
};

typedef C<MyT> C_MyT;

int main(int argc, char** argv) {
    V* o2 = C_MyT::new_();
    assert(dynamic_cast<C_MyT*> (o2)); // failure in GCC, success in CLang
    return 0;
}
Martin
  • 9,089
  • 11
  • 52
  • 87

1 Answers1

2

g++ appears to be behaving correctly. See Dynamic downcast on private inheritance within private scope which has a good answer describing this.

Community
  • 1
  • 1
Gareth McCaughan
  • 19,888
  • 1
  • 41
  • 62