From 66f4084caafd3dc0fd74bf6a7f57b785a5a1e051 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 3 Sep 2015 17:36:08 +0200 Subject: Diagnose base classes that are defined after us This can happen with templates/CRP --- odb/validator.cxx | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/odb/validator.cxx b/odb/validator.cxx index 6975736..51768a0 100644 --- a/odb/validator.cxx +++ b/odb/validator.cxx @@ -444,7 +444,54 @@ namespace virtual void traverse (type& c) { - switch (class_kind (c)) + class_kind_type ck (class_kind (c)); + + if (ck != class_other) + { + for (type::inherits_iterator i (c.inherits_begin ()); + i != c.inherits_end (); ++i) + { + type& b (i->base ()); + + if (class_kind (b) == class_other) + continue; + + location_t cl; + location_t bl; + + // If we are in the same file, then use real locations (as + // opposed to definition locations) since that's the order + // in which we will be generating the code. + // + if (class_file (c) == class_file (b)) + { + cl = class_real_location (c); + bl = class_real_location (b); + } + else + { + cl = class_location (c); + bl = class_location (b); + } + + if (cl < bl) + { + // We cannot use class_name() for b since it might not have + // yet been processed (tree-hint). + // + error (cl) << "base class " << b.name () << " must " + << "be defined before derived class " << class_name (c) + << endl; + + info (bl) << "class " << b.name () << " is define here" + << endl; + + valid_ = false; + } + } + } + + switch (ck) { case class_object: names (c); @@ -1121,7 +1168,6 @@ namespace } } - virtual void traverse (type& m) { -- cgit v1.1