glr2.cc: example: address Clang warnings

ast.hh:24:7: error: 'Node' has no out-of-line virtual method definitions; its vtable will be emitted in every translation unit [-Werror,-Wweak-vtables]
    class Node
          ^
    ast.hh:57:7: error: 'Nterm' has no out-of-line virtual method definitions; its vtable will be emitted in every translation unit [-Werror,-Wweak-vtables]
    class Nterm : public Node
          ^
    ast.hh:102:7: error: 'Term' has no out-of-line virtual method definitions; its vtable will be emitted in every translation unit [-Werror,-Wweak-vtables]
    class Term : public Node
          ^

* examples/c++/glr/ast.hh: Define the destructors out of the class
definition.
This does not change anything, it is still in the header, but that
does pacify clang.
This commit is contained in:
Akim Demaille
2020-12-19 07:26:35 +01:00
parent b33817f8bb
commit d6fbeb2798

View File

@@ -11,8 +11,7 @@ public:
: parents_ (0)
{}
virtual ~Node ()
{}
virtual ~Node ();
void free ()
{
@@ -30,6 +29,9 @@ protected:
int parents_;
};
Node::~Node ()
{}
static std::ostream&
operator<< (std::ostream& o, const Node &node)
@@ -55,12 +57,7 @@ public:
child2->parents_ += 1;
}
~Nterm ()
{
for (int i = 0; i < 3; ++i)
if (children_[i])
children_[i]->free ();
}
~Nterm ();
std::ostream& print (std::ostream& o) const
{
@@ -82,12 +79,21 @@ private:
Node *children_[3];
};
Nterm::~Nterm ()
{
for (int i = 0; i < 3; ++i)
if (children_[i])
children_[i]->free ();
}
class Term : public Node
{
public:
Term (const std::string &text)
: text_ (text)
{}
~Term();
std::ostream& print (std::ostream& o) const
{
@@ -98,3 +104,7 @@ public:
private:
std::string text_;
};
Term::~Term ()
{
}