summaryrefslogtreecommitdiff
path: root/odb
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2024-04-30 14:35:45 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2024-04-30 14:35:45 +0200
commit2a8ca82757ddaafe72137171f560c12e6d009f1e (patch)
tree14c38c501296c733310a7a2efd3d760537607502 /odb
parent617212e2dd92f1c7cae489a977d43b8a14f1c24b (diff)
Fix Clang -Wno-undefined-var-template in dynamic multi-database support code
Note that after this change we can no longer support multi-file circular dependencies in this mode since we need to generate extern template declarations involving classes that may participate in the cycle (see now excluded odb-tests/common/circular/multiple/).
Diffstat (limited to 'odb')
-rw-r--r--odb/odb/common-query.cxx41
-rw-r--r--odb/odb/context.cxx9
2 files changed, 41 insertions, 9 deletions
diff --git a/odb/odb/common-query.cxx b/odb/odb/common-query.cxx
index 517c92c..0b5d063 100644
--- a/odb/odb/common-query.cxx
+++ b/odb/odb/common-query.cxx
@@ -1031,14 +1031,30 @@ traverse (type& c)
{
// If we have the extern symbol, generate extern template declarations.
//
- if (!ext.empty ())
+ // Without a declaration of explicit template instantiation Clang issues
+ // -Wundefined-var-template. Note that extern template is only available
+ // since C++11 and this only appears to be an issue in dynamic multi-
+ // database support for id_common.
+ //
+ // Note also that this break our support for multi-file circular
+ // dependencies (see odb-tests/common/circule/multiple/).
+ //
+ if (!ext.empty () ||
+ (multi_dynamic &&
+ db == database::common &&
+ options.std () >= cxx_version::cxx11))
{
bool has_ptr (has_a (c, test_pointer | exclude_base));
bool reuse_abst (abstract (c) && !polymorphic (c));
if (has_ptr || !reuse_abst)
{
- os << "#ifdef " << ext << endl
+ const string& guard (
+ !ext.empty ()
+ ? ext
+ : make_guard ("ODB_" + db.string () + "_QUERY_COLUMNS_DEF"));
+
+ os << (!ext.empty () ? "#ifdef " : "#ifndef ") << guard << endl
<< endl;
if (has_ptr)
@@ -1055,7 +1071,7 @@ traverse (type& c)
if (!reuse_abst)
generate_inst (c);
- os << "#endif // " << ext << endl
+ os << "#endif // " << guard << endl
<< endl;
}
}
@@ -1128,7 +1144,7 @@ generate_inst (type& c)
string const& type (class_fq_name (c));
// Explicit template instantiations. Here is what we need to
- // instantiate
+ // instantiate:
//
// 1. Reuse inheritance bases all the way to the ultimate base.
// Unlike poly inheritance, reuse inheritance uses the table
@@ -1216,14 +1232,25 @@ generate_decl (type& c)
// Do it before query_columns since the inheritance will trigger
// instantiation and we won't be able to change visibility (GCC).
//
- if (obj_count != 0 && multi_dynamic && !ext.empty ())
+ // See query_columns_type::traverse() for background.
+ //
+ if (obj_count != 0 && multi_dynamic &&
+ (!ext.empty () ||
+ (multi_dynamic &&
+ db == database::common &&
+ options.std () >= cxx_version::cxx11)))
{
- os << "#ifdef " << ext << endl
+ const string& guard (
+ !ext.empty ()
+ ? ext
+ : make_guard ("ODB_" + db.string () + "_QUERY_COLUMNS_DEF"));
+
+ os << (!ext.empty () ? "#ifdef " : "#ifndef ") << guard << endl
<< endl;
generate_inst (c);
- os << "#endif // " << ext << endl
+ os << "#endif // " << guard << endl
<< endl;
}
diff --git a/odb/odb/context.cxx b/odb/odb/context.cxx
index 13fc1b3..f678e64 100644
--- a/odb/odb/context.cxx
+++ b/odb/odb/context.cxx
@@ -2961,8 +2961,13 @@ strlit (string const& str)
void context::
inst_header (bool decl, bool omit_exp)
{
- if (decl && !ext.empty ())
- os << ext << " ";
+ if (decl)
+ {
+ if (!ext.empty ())
+ os << ext << " ";
+ else
+ os << "extern ";
+ }
os << "template struct";