https://llvm.org/bugs/show_bug.cgi?id=31270
Bug ID: 31270 Summary: Pure virtual function called Product: clang Version: trunk Hardware: PC OS: Linux Status: NEW Severity: normal Priority: P Component: Frontend Assignee: unassignedclangb...@nondot.org Reporter: marco.di...@gmail.com CC: llvm-bugs@lists.llvm.org Classification: Unclassified It seems that both MSVC and gcc reject this code by detecting the abstract class instantiation while clang 4.0 compiles it and runs to a "Pure virtual function called" error: #include <vector> #include <iostream> using namespace std; template <typename P> class Surface { public: virtual int distance(const P& from, const P& to) const = 0; virtual bool check(const vector<P>& path, const P& from, const P& to) const = 0; virtual vector<P> lookAround(const P& at) const = 0; }; class PlanarSurface : public Surface<pair<int, int>> { public: using point_type = pair<int, int>; int distance(const point_type&, const point_type&) const override { return 42; } bool check(const vector<point_type>&, const point_type&, const point_type&) const override { return true; // there would be the check } vector<point_type> lookAround(const point_type&) const override { vector<point_type> result; //... return result; } }; template <typename P> class Robot { public: Robot(const Surface<P>& s): surface(s) {} vector<P> findPath(const P& from, const P& to) { auto path = searchPath(from, to); if (surface.check(path, from, to)) { return path; } throw runtime_error("path not found or incorrect"); } private: virtual vector<P> searchPath(const P& from, const P& to) = 0; protected: const Surface<P>& surface; }; template <typename P> class MyRobot: public Robot<P> { public: MyRobot(Surface<P> m): Robot<P>(m) {} private: vector<P> searchPath(const P& from, const P& to) override { vector<P> result; // ... // use one of surface's virtual methods auto dist = this->surface.distance(from, to); // Pure virtual function called! cout << dist << endl; // ... return result; } }; int main() { PlanarSurface plane; MyRobot<pair<int, int>> robot(plane); robot.findPath({1,2}, {3,4}); return 0; } (http://melpon.org/wandbox/permlink/6bsWOwweJTRzMwLA) Not sure if the diagnostic is mandatory but it would surely be a nice-to-have feature. -- You are receiving this mail because: You are on the CC list for the bug.
_______________________________________________ llvm-bugs mailing list llvm-bugs@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs