From ddf83435904356eeb95f1d3ef7dd6959b4731061 Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 16 Oct 2015 15:38:28 +0200 Subject: [PATCH] Reorganise explicit template instantiations so that it always happens in the .cxx file, while remaining backward compatible with MSVC's standards-breaking implementation --- dtool/src/dtoolbase/dtoolbase.h | 16 +++++++++++++--- dtool/src/prc/notifyCategoryProxy.h | 12 +----------- makepanda/makepanda.py | 2 -- panda/src/chan/animChannel.cxx | 3 +++ panda/src/chan/movingPartMatrix.cxx | 2 ++ panda/src/chan/movingPartScalar.cxx | 2 ++ panda/src/egg/eggMorph.h | 4 ++++ panda/src/egg/pt_EggMaterial.cxx | 4 ++++ panda/src/egg/pt_EggTexture.cxx | 4 ++++ panda/src/egg/pt_EggVertex.cxx | 4 ++++ panda/src/event/eventParameter.cxx | 3 +++ panda/src/event/pt_Event.cxx | 4 ++++ panda/src/express/pta_double.cxx | 5 +++++ panda/src/express/pta_float.cxx | 5 +++++ panda/src/express/pta_int.cxx | 5 +++++ panda/src/express/pta_uchar.cxx | 5 +++++ panda/src/mathutil/pta_LMatrix3.cxx | 10 ++++++++++ panda/src/mathutil/pta_LMatrix4.cxx | 10 ++++++++++ panda/src/mathutil/pta_LVecBase2.cxx | 15 +++++++++++++++ panda/src/mathutil/pta_LVecBase3.cxx | 15 +++++++++++++++ panda/src/mathutil/pta_LVecBase4.cxx | 15 +++++++++++++++ panda/src/net/datagramGeneratorNet.cxx | 2 ++ panda/src/net/queuedConnectionListener.cxx | 2 ++ panda/src/net/queuedConnectionManager.cxx | 2 ++ panda/src/net/queuedConnectionReader.cxx | 2 ++ panda/src/putil/bitMask.cxx | 4 ++++ panda/src/putil/doubleBitMask.cxx | 2 ++ panda/src/putil/paramValue.cxx | 21 +++++++++++++++++++++ panda/src/putil/pta_ushort.cxx | 5 +++++ 29 files changed, 169 insertions(+), 16 deletions(-) diff --git a/dtool/src/dtoolbase/dtoolbase.h b/dtool/src/dtoolbase/dtoolbase.h index 68975b5877..75bad76d5b 100644 --- a/dtool/src/dtoolbase/dtoolbase.h +++ b/dtool/src/dtoolbase/dtoolbase.h @@ -440,13 +440,23 @@ #define EXPORT_CLASS #define IMPORT_CLASS #endif + /* "extern template" is now part of the C++11 standard. */ -#if !defined(CPPPARSER) && !defined(LINK_ALL_STATIC) +#if defined(CPPPARSER) || defined(LINK_ALL_STATIC) +#define EXPORT_TEMPL +#define IMPORT_TEMPL +#elif defined(_MSC_VER) +/* Nowadays, we'd define both of these as "extern" in all cases, so that + the header file always marks the symbol as "extern" and the .cxx file + explicitly instantiates it. However, MSVC versions before 2013 break + the spec by explicitly disallowing it, so we have to instantiate the + class from the header file. Fortunately, its linker is okay with the + duplicate template instantiations that this causes. */ #define EXPORT_TEMPL #define IMPORT_TEMPL extern #else -#define EXPORT_TEMPL -#define IMPORT_TEMPL +#define EXPORT_TEMPL extern +#define IMPORT_TEMPL extern #endif #ifdef __cplusplus diff --git a/dtool/src/prc/notifyCategoryProxy.h b/dtool/src/prc/notifyCategoryProxy.h index 9e3c239c5e..de9ada490a 100644 --- a/dtool/src/prc/notifyCategoryProxy.h +++ b/dtool/src/prc/notifyCategoryProxy.h @@ -127,16 +127,6 @@ INLINE ostream &operator << (ostream &out, NotifyCategoryProxy &pro #ifdef CPPPARSER #define NotifyCategoryDecl(basename, expcl, exptp) -#elif defined(WIN32_VC) -// MSVC's rules for extern template classes differ slightly. -#define NotifyCategoryDecl(basename, expcl, exptp) \ - class expcl NotifyCategoryGetCategory_ ## basename { \ - public: \ - NotifyCategoryGetCategory_ ## basename(); \ - static NotifyCategory *get_category(); \ - }; \ - EXPORT_TEMPLATE_CLASS(expcl, exptp, NotifyCategoryProxy); \ - extern expcl NotifyCategoryProxy basename ## _cat; #else #define NotifyCategoryDecl(basename, expcl, exptp) \ class expcl NotifyCategoryGetCategory_ ## basename { \ @@ -144,7 +134,7 @@ INLINE ostream &operator << (ostream &out, NotifyCategoryProxy &pro NotifyCategoryGetCategory_ ## basename(); \ static NotifyCategory *get_category(); \ }; \ - EXPORT_TEMPLATE_CLASS(expcl, extern, NotifyCategoryProxy); \ + EXPORT_TEMPLATE_CLASS(expcl, exptp, NotifyCategoryProxy); \ extern expcl NotifyCategoryProxy basename ## _cat; #endif diff --git a/makepanda/makepanda.py b/makepanda/makepanda.py index 1fd35793fb..145664851d 100755 --- a/makepanda/makepanda.py +++ b/makepanda/makepanda.py @@ -1650,8 +1650,6 @@ def CompileLink(dll, obj, opts): else: cmd += " -pthread" - cmd += " -Wl,-allow-multiple-definition" - if LDFLAGS != "": cmd += " " + LDFLAGS diff --git a/panda/src/chan/animChannel.cxx b/panda/src/chan/animChannel.cxx index c85faed849..fb710994ee 100644 --- a/panda/src/chan/animChannel.cxx +++ b/panda/src/chan/animChannel.cxx @@ -22,6 +22,9 @@ #pragma implementation #endif +template class AnimChannel; +template class AnimChannel; + //////////////////////////////////////////////////////////////////// // Function: ACMatrixSwitchType::output_value // Access: Public, Static diff --git a/panda/src/chan/movingPartMatrix.cxx b/panda/src/chan/movingPartMatrix.cxx index de9d60e2a0..fc20b896c9 100644 --- a/panda/src/chan/movingPartMatrix.cxx +++ b/panda/src/chan/movingPartMatrix.cxx @@ -28,6 +28,8 @@ #pragma implementation #endif +template class MovingPart; + TypeHandle MovingPartMatrix::_type_handle; //////////////////////////////////////////////////////////////////// diff --git a/panda/src/chan/movingPartScalar.cxx b/panda/src/chan/movingPartScalar.cxx index 7f5260c7a7..727b011b5b 100644 --- a/panda/src/chan/movingPartScalar.cxx +++ b/panda/src/chan/movingPartScalar.cxx @@ -26,6 +26,8 @@ #pragma implementation #endif +template class MovingPart; + TypeHandle MovingPartScalar::_type_handle; //////////////////////////////////////////////////////////////////// diff --git a/panda/src/egg/eggMorph.h b/panda/src/egg/eggMorph.h index 4bf5cb37b8..04644e9ec7 100644 --- a/panda/src/egg/eggMorph.h +++ b/panda/src/egg/eggMorph.h @@ -49,8 +49,12 @@ private: Parameter _offset; }; +// I'd love to export these, but it produces a strange linker issue +// with Mac OS X's version of GCC. We'll do it only on Windows, then. +#ifdef _MSC_VER EXPORT_TEMPLATE_CLASS(EXPCL_PANDAEGG, EXPTP_PANDAEGG, EggMorph); EXPORT_TEMPLATE_CLASS(EXPCL_PANDAEGG, EXPTP_PANDAEGG, EggMorph); +#endif typedef EggMorph EggMorphVertex; typedef EggMorph EggMorphNormal; diff --git a/panda/src/egg/pt_EggMaterial.cxx b/panda/src/egg/pt_EggMaterial.cxx index f85b8e4194..1a4207000f 100644 --- a/panda/src/egg/pt_EggMaterial.cxx +++ b/panda/src/egg/pt_EggMaterial.cxx @@ -18,3 +18,7 @@ #ifdef __GNUC__ #pragma implementation #endif + +template class PointerToBase; +template class PointerTo; +template class ConstPointerTo; diff --git a/panda/src/egg/pt_EggTexture.cxx b/panda/src/egg/pt_EggTexture.cxx index 9c8f4b2711..4cff50aa93 100644 --- a/panda/src/egg/pt_EggTexture.cxx +++ b/panda/src/egg/pt_EggTexture.cxx @@ -18,3 +18,7 @@ #ifdef __GNUC__ #pragma implementation #endif + +template class PointerToBase; +template class PointerTo; +template class ConstPointerTo; diff --git a/panda/src/egg/pt_EggVertex.cxx b/panda/src/egg/pt_EggVertex.cxx index 7fce6ac7ea..d5c7057b0b 100644 --- a/panda/src/egg/pt_EggVertex.cxx +++ b/panda/src/egg/pt_EggVertex.cxx @@ -18,3 +18,7 @@ #ifdef __GNUC__ #pragma implementation #endif + +template class PointerToBase; +template class PointerTo; +template class ConstPointerTo; diff --git a/panda/src/event/eventParameter.cxx b/panda/src/event/eventParameter.cxx index 76bef88f9b..115b6f7b8f 100644 --- a/panda/src/event/eventParameter.cxx +++ b/panda/src/event/eventParameter.cxx @@ -20,6 +20,9 @@ #pragma implementation #endif +template class ParamValue; +template class ParamValue; + //////////////////////////////////////////////////////////////////// // Function: EventParameter::output // Access: Published diff --git a/panda/src/event/pt_Event.cxx b/panda/src/event/pt_Event.cxx index 5dea3358d1..5e4d1b4f95 100644 --- a/panda/src/event/pt_Event.cxx +++ b/panda/src/event/pt_Event.cxx @@ -18,3 +18,7 @@ #ifdef __GNUC__ #pragma implementation #endif + +template class PointerToBase; +template class PointerTo; +template class ConstPointerTo; diff --git a/panda/src/express/pta_double.cxx b/panda/src/express/pta_double.cxx index 679aa836f0..951be4b584 100644 --- a/panda/src/express/pta_double.cxx +++ b/panda/src/express/pta_double.cxx @@ -18,3 +18,8 @@ #ifdef __GNUC__ #pragma implementation #endif + +template class PointerToBase >; +template class PointerToArrayBase; +template class PointerToArray; +template class ConstPointerToArray; diff --git a/panda/src/express/pta_float.cxx b/panda/src/express/pta_float.cxx index 468be7a730..1483711420 100644 --- a/panda/src/express/pta_float.cxx +++ b/panda/src/express/pta_float.cxx @@ -18,3 +18,8 @@ #ifdef __GNUC__ #pragma implementation #endif + +template class PointerToBase >; +template class PointerToArrayBase; +template class PointerToArray; +template class ConstPointerToArray; diff --git a/panda/src/express/pta_int.cxx b/panda/src/express/pta_int.cxx index 7aec867a67..206e87c3db 100644 --- a/panda/src/express/pta_int.cxx +++ b/panda/src/express/pta_int.cxx @@ -18,3 +18,8 @@ #ifdef __GNUC__ #pragma implementation #endif + +template class PointerToBase >; +template class PointerToArrayBase; +template class PointerToArray; +template class ConstPointerToArray; diff --git a/panda/src/express/pta_uchar.cxx b/panda/src/express/pta_uchar.cxx index 01c09858b6..4abaad3fa5 100644 --- a/panda/src/express/pta_uchar.cxx +++ b/panda/src/express/pta_uchar.cxx @@ -18,3 +18,8 @@ #ifdef __GNUC__ #pragma implementation #endif + +template class PointerToBase >; +template class PointerToArrayBase; +template class PointerToArray; +template class ConstPointerToArray; diff --git a/panda/src/mathutil/pta_LMatrix3.cxx b/panda/src/mathutil/pta_LMatrix3.cxx index 7e71a7a8ac..42382e1295 100644 --- a/panda/src/mathutil/pta_LMatrix3.cxx +++ b/panda/src/mathutil/pta_LMatrix3.cxx @@ -18,3 +18,13 @@ #ifdef __GNUC__ #pragma implementation #endif + +template class PointerToBase >; +template class PointerToArrayBase; +template class PointerToArray; +template class ConstPointerToArray; + +template class PointerToBase >; +template class PointerToArrayBase; +template class PointerToArray; +template class ConstPointerToArray; diff --git a/panda/src/mathutil/pta_LMatrix4.cxx b/panda/src/mathutil/pta_LMatrix4.cxx index a171eb7e35..5ba0c1b9a8 100644 --- a/panda/src/mathutil/pta_LMatrix4.cxx +++ b/panda/src/mathutil/pta_LMatrix4.cxx @@ -18,3 +18,13 @@ #ifdef __GNUC__ #pragma implementation #endif + +template class PointerToBase >; +template class PointerToArrayBase; +template class PointerToArray; +template class ConstPointerToArray; + +template class PointerToBase >; +template class PointerToArrayBase; +template class PointerToArray; +template class ConstPointerToArray; diff --git a/panda/src/mathutil/pta_LVecBase2.cxx b/panda/src/mathutil/pta_LVecBase2.cxx index 4e60170a8d..cbf9ace24f 100644 --- a/panda/src/mathutil/pta_LVecBase2.cxx +++ b/panda/src/mathutil/pta_LVecBase2.cxx @@ -18,3 +18,18 @@ #ifdef __GNUC__ #pragma implementation #endif + +template class PointerToBase >; +template class PointerToArrayBase; +template class PointerToArray; +template class ConstPointerToArray; + +template class PointerToBase >; +template class PointerToArrayBase; +template class PointerToArray; +template class ConstPointerToArray; + +template class PointerToBase >; +template class PointerToArrayBase; +template class PointerToArray; +template class ConstPointerToArray; diff --git a/panda/src/mathutil/pta_LVecBase3.cxx b/panda/src/mathutil/pta_LVecBase3.cxx index ab535d218f..d851708d2c 100644 --- a/panda/src/mathutil/pta_LVecBase3.cxx +++ b/panda/src/mathutil/pta_LVecBase3.cxx @@ -18,3 +18,18 @@ #ifdef __GNUC__ #pragma implementation #endif + +template class PointerToBase >; +template class PointerToArrayBase; +template class PointerToArray; +template class ConstPointerToArray; + +template class PointerToBase >; +template class PointerToArrayBase; +template class PointerToArray; +template class ConstPointerToArray; + +template class PointerToBase >; +template class PointerToArrayBase; +template class PointerToArray; +template class ConstPointerToArray; diff --git a/panda/src/mathutil/pta_LVecBase4.cxx b/panda/src/mathutil/pta_LVecBase4.cxx index 8f133e36de..dc8de69ebe 100644 --- a/panda/src/mathutil/pta_LVecBase4.cxx +++ b/panda/src/mathutil/pta_LVecBase4.cxx @@ -18,3 +18,18 @@ #ifdef __GNUC__ #pragma implementation #endif + +template class PointerToBase >; +template class PointerToArrayBase; +template class PointerToArray; +template class ConstPointerToArray; + +template class PointerToBase >; +template class PointerToArrayBase; +template class PointerToArray; +template class ConstPointerToArray; + +template class PointerToBase >; +template class PointerToArrayBase; +template class PointerToArray; +template class ConstPointerToArray; diff --git a/panda/src/net/datagramGeneratorNet.cxx b/panda/src/net/datagramGeneratorNet.cxx index 963d59985e..ebcd9ed5c0 100644 --- a/panda/src/net/datagramGeneratorNet.cxx +++ b/panda/src/net/datagramGeneratorNet.cxx @@ -18,6 +18,8 @@ #include "mutexHolder.h" #include "lightMutexHolder.h" +template class QueuedReturn; + //////////////////////////////////////////////////////////////////// // Function: DatagramGeneratorNet::Constructor // Access: Published diff --git a/panda/src/net/queuedConnectionListener.cxx b/panda/src/net/queuedConnectionListener.cxx index 24ad4da190..49f05ff4b5 100644 --- a/panda/src/net/queuedConnectionListener.cxx +++ b/panda/src/net/queuedConnectionListener.cxx @@ -15,6 +15,8 @@ #include "queuedConnectionListener.h" #include "config_net.h" +template class QueuedReturn; + //////////////////////////////////////////////////////////////////// // Function: QueuedConnectionListener::Constructor // Access: Public diff --git a/panda/src/net/queuedConnectionManager.cxx b/panda/src/net/queuedConnectionManager.cxx index 9a94b55094..2a7993dced 100644 --- a/panda/src/net/queuedConnectionManager.cxx +++ b/panda/src/net/queuedConnectionManager.cxx @@ -16,6 +16,8 @@ #include +template class QueuedReturn< PT(Connection) >; + //////////////////////////////////////////////////////////////////// // Function: QueuedConnectionManager::Constructor // Access: Public diff --git a/panda/src/net/queuedConnectionReader.cxx b/panda/src/net/queuedConnectionReader.cxx index 99b18721ac..2baa90ad72 100644 --- a/panda/src/net/queuedConnectionReader.cxx +++ b/panda/src/net/queuedConnectionReader.cxx @@ -17,6 +17,8 @@ #include "trueClock.h" #include "lightMutexHolder.h" +template class QueuedReturn; + //////////////////////////////////////////////////////////////////// // Function: QueuedConnectionReader::Constructor // Access: Published diff --git a/panda/src/putil/bitMask.cxx b/panda/src/putil/bitMask.cxx index 5a7873752f..11c14414b2 100644 --- a/panda/src/putil/bitMask.cxx +++ b/panda/src/putil/bitMask.cxx @@ -18,3 +18,7 @@ #ifdef __GNUC__ #pragma implementation #endif + +template class BitMask; +template class BitMask; +template class BitMask; diff --git a/panda/src/putil/doubleBitMask.cxx b/panda/src/putil/doubleBitMask.cxx index 8d27d25e12..81fab4f3b2 100644 --- a/panda/src/putil/doubleBitMask.cxx +++ b/panda/src/putil/doubleBitMask.cxx @@ -19,3 +19,5 @@ #pragma implementation #endif +template class DoubleBitMask; +template class DoubleBitMask; diff --git a/panda/src/putil/paramValue.cxx b/panda/src/putil/paramValue.cxx index c8482dc409..3f67ee1de9 100644 --- a/panda/src/putil/paramValue.cxx +++ b/panda/src/putil/paramValue.cxx @@ -20,6 +20,27 @@ #pragma implementation #endif +template class ParamValue; +template class ParamValue; + +template class ParamValue; +template class ParamValue; +template class ParamValue; + +template class ParamValue; +template class ParamValue; +template class ParamValue; + +template class ParamValue; +template class ParamValue; +template class ParamValue; + +template class ParamValue; +template class ParamValue; + +template class ParamValue; +template class ParamValue; + TypeHandle ParamValueBase::_type_handle; TypeHandle ParamTypedRefCount::_type_handle; diff --git a/panda/src/putil/pta_ushort.cxx b/panda/src/putil/pta_ushort.cxx index f118a29cb4..1b16926a64 100644 --- a/panda/src/putil/pta_ushort.cxx +++ b/panda/src/putil/pta_ushort.cxx @@ -18,3 +18,8 @@ #ifdef __GNUC__ #pragma implementation #endif + +template class PointerToBase >; +template class PointerToArrayBase; +template class PointerToArray; +template class ConstPointerToArray;