From 6b0c0a497724dd77b59ec4ad4002573be5569b7c Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Sun, 25 May 2025 17:52:12 -0600 Subject: [PATCH] Remove a template instantiation optimization when building modules. --- include/deal.II/dofs/dof_handler.h | 13 ++++++++++++- include/deal.II/grid/tria.h | 12 ++++++++++++ include/deal.II/hp/mapping_collection.h | 18 ++++++++++++++---- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/include/deal.II/dofs/dof_handler.h b/include/deal.II/dofs/dof_handler.h index a4173a090e..0d46cddea9 100644 --- a/include/deal.II/dofs/dof_handler.h +++ b/include/deal.II/dofs/dof_handler.h @@ -2147,13 +2147,24 @@ inline types::global_dof_index +// Declare the existence of explicit instantiations of the class +// above. This is not strictly necessary, but tells the compiler to +// avoid instantiating templates that we know are instantiated in +// .cc files and so can be referenced without implicit +// instantiations. +// +// Unfortunately, this does not seem to work when building modules +// because the compiler (well, Clang at least) then just doesn't +// instantiate these classes at all, even though their members are +// defined and explicitly instantiated in a .cc file. +# ifndef DEAL_II_BUILDING_CXX20_MODULE extern template class DoFHandler<1, 1>; extern template class DoFHandler<1, 2>; extern template class DoFHandler<1, 3>; extern template class DoFHandler<2, 2>; extern template class DoFHandler<2, 3>; extern template class DoFHandler<3, 3>; - +# endif #endif // DOXYGEN diff --git a/include/deal.II/grid/tria.h b/include/deal.II/grid/tria.h index 8701067fcb..7cf46b6066 100644 --- a/include/deal.II/grid/tria.h +++ b/include/deal.II/grid/tria.h @@ -4937,12 +4937,24 @@ bool Triangulation<1, 3>::prepare_coarsening_and_refinement(); +// Declare the existence of explicit instantiations of the class +// above. This is not strictly necessary, but tells the compiler to +// avoid instantiating templates that we know are instantiated in +// .cc files and so can be referenced without implicit +// instantiations. +// +// Unfortunately, this does not seem to work when building modules +// because the compiler (well, Clang at least) then just doesn't +// instantiate these classes at all, even though their members are +// defined and explicitly instantiated in a .cc file. +# ifndef DEAL_II_BUILDING_CXX20_MODULE extern template class Triangulation<1, 1>; extern template class Triangulation<1, 2>; extern template class Triangulation<1, 3>; extern template class Triangulation<2, 2>; extern template class Triangulation<2, 3>; extern template class Triangulation<3, 3>; +# endif #endif // DOXYGEN diff --git a/include/deal.II/hp/mapping_collection.h b/include/deal.II/hp/mapping_collection.h index af4acc9906..b645c89a2e 100644 --- a/include/deal.II/hp/mapping_collection.h +++ b/include/deal.II/hp/mapping_collection.h @@ -182,9 +182,18 @@ namespace hp #ifndef DOXYGEN - // Declare the existence of explicit instantiations of the class - // above to avoid certain warnings issues by clang and - // newer (LLVM-based) Intel compilers: +// Declare the existence of explicit instantiations of the class +// above. This is not strictly necessary, but tells the compiler to +// avoid instantiating templates that we know are instantiated in +// .cc files and so can be referenced without implicit +// instantiations. In the current case, this also avoids certain +// warnings issues by clang and newer (LLVM-based) Intel compilers. +// +// Unfortunately, this does not seem to work when building modules +// because the compiler (well, Clang at least) then just doesn't +// instantiate these classes at all, even though their members are +// defined and explicitly instantiated in a .cc file. +# ifndef DEAL_II_BUILDING_CXX20_MODULE extern template struct StaticMappingQ1<1, 1>; extern template struct StaticMappingQ1<1, 2>; extern template struct StaticMappingQ1<1, 3>; @@ -192,7 +201,7 @@ namespace hp extern template struct StaticMappingQ1<2, 3>; extern template struct StaticMappingQ1<3, 3>; -# ifndef _MSC_VER +# ifndef _MSC_VER extern template MappingCollection<1, 1> StaticMappingQ1<1, 1>::mapping_collection; extern template MappingCollection<1, 2> @@ -205,6 +214,7 @@ namespace hp StaticMappingQ1<2, 3>::mapping_collection; extern template MappingCollection<3, 3> StaticMappingQ1<3, 3>::mapping_collection; +# endif # endif #endif -- 2.39.5