From e4ce907c1ddda79861aedf2200e74a6c89c64f74 Mon Sep 17 00:00:00 2001 From: Kp Date: Wed, 7 Jun 2017 02:44:54 +0000 Subject: [PATCH] Reduce scope of explicit instantiations --- similar/main/mglobal.cpp | 51 ++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/similar/main/mglobal.cpp b/similar/main/mglobal.cpp index bf93bf9aa..7f65a6da1 100644 --- a/similar/main/mglobal.cpp +++ b/similar/main/mglobal.cpp @@ -102,11 +102,48 @@ valptridx::array_managed_type Triggers; valptridx::array_managed_type Walls; } -template class valptridx; -#if defined(DXX_BUILD_DESCENT_II) -template class valptridx; +/* + * If not specified otherwise by the user, enable full instantiation if + * the compiler optimizer is not enabled. This is required because + * non-optimized builds contain link time references to functions that + * are not used. + * + * Force full instantiation for non-optimized builds so that these + * references are satisfied. For optimized builds, instantiate only the + * classes that are known to be used. + */ +#ifndef DXX_VALPTRIDX_ENABLE_FULL_TEMPLATE_INSTANTIATION +#define DXX_VALPTRIDX_ENABLE_FULL_TEMPLATE_INSTANTIATION !(defined(__OPTIMIZE__) && __OPTIMIZE__ > 0) +#endif + +#if DXX_VALPTRIDX_ENABLE_FULL_TEMPLATE_INSTANTIATION +template class valptridx; +#if defined(DXX_BUILD_DESCENT_II) +template class valptridx; +#endif +template class valptridx; +template class valptridx; +template class valptridx; +template class valptridx; + +#else + +#if DXX_VALPTRIDX_REPORT_ERROR_STYLE == DXX_VALPTRIDX_ERROR_STYLE_TREAT_AS_EXCEPTION +template class valptridx::index_range_exception; +#if defined(DXX_BUILD_DESCENT_II) +template class valptridx::index_range_exception; +#endif + +template class valptridx::index_mismatch_exception; +template class valptridx::index_range_exception; +template class valptridx::null_pointer_exception; + +template class valptridx::index_mismatch_exception; +template class valptridx::index_range_exception; +template class valptridx::null_pointer_exception; + +template class valptridx::index_range_exception; +template class valptridx::index_range_exception; +#endif + #endif -template class valptridx; -template class valptridx; -template class valptridx; -template class valptridx;