<html>
<head>
<base href="https://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - Pure virtual function called"
href="https://llvm.org/bugs/show_bug.cgi?id=31270">31270</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Pure virtual function called
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Frontend
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>marco.diiga@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>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;
}
(<a href="http://melpon.org/wandbox/permlink/6bsWOwweJTRzMwLA">http://melpon.org/wandbox/permlink/6bsWOwweJTRzMwLA</a>)
Not sure if the diagnostic is mandatory but it would surely be a nice-to-have
feature.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>