Skip to content

Commit

Permalink
glr2.cc: example: address Clang warnings
Browse files Browse the repository at this point in the history
    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.
  • Loading branch information
akimd committed Dec 19, 2020
1 parent b33817f commit d6fbeb2
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions examples/c++/glr/ast.hh
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ public:
: parents_ (0)
{}

virtual ~Node ()
{}
virtual ~Node ();

void free ()
{
Expand All @@ -30,6 +29,9 @@ protected:
int parents_;
};

Node::~Node ()
{}


static std::ostream&
operator<< (std::ostream& o, const Node &node)
Expand All @@ -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
{
Expand All @@ -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
{
Expand All @@ -98,3 +104,7 @@ public:
private:
std::string text_;
};

Term::~Term ()
{
}

0 comments on commit d6fbeb2

Please sign in to comment.