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