From 2add60a4c4092fd5e429afe885ace09ea87c3653 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Fri, 14 Apr 2017 17:54:01 +0300 Subject: [PATCH] Single RUNTIME_CLASS() macro for classes and templates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The main purpose of this is to fix compilation errors with GCC/Clang src/dobject.h:87:48: error: expected primary-expression before ‘)’ token --- src/actor.h | 8 ++++---- src/dobject.h | 3 +-- src/dthinker.h | 4 ++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/actor.h b/src/actor.h index 1eda53028..bc65144da 100644 --- a/src/actor.h +++ b/src/actor.h @@ -739,7 +739,7 @@ public: AInventory *FindInventory (FName type, bool subclass = false); template T *FindInventory () { - return static_cast (FindInventory (RUNTIME_TEMPLATE_CLASS(T))); + return static_cast (FindInventory (RUNTIME_CLASS(T))); } // Adds one item of a particular type. Returns NULL if it could not be added. @@ -1512,7 +1512,7 @@ public: do { actor = FActorIterator::Next (); - } while (actor && !actor->IsKindOf (RUNTIME_TEMPLATE_CLASS(T))); + } while (actor && !actor->IsKindOf (RUNTIME_CLASS(T))); return static_cast(actor); } }; @@ -1563,12 +1563,12 @@ inline AActor *Spawn(FName type, const DVector3 &pos, replace_t allowreplacement template inline T *Spawn(const DVector3 &pos, replace_t allowreplacement) { - return static_cast(AActor::StaticSpawn(RUNTIME_TEMPLATE_CLASS(T), pos, allowreplacement)); + return static_cast(AActor::StaticSpawn(RUNTIME_CLASS(T), pos, allowreplacement)); } template inline T *Spawn() // for inventory items we do not need coordinates and replacement info. { - return static_cast(AActor::StaticSpawn(RUNTIME_TEMPLATE_CLASS(T), DVector3(0, 0, 0), NO_REPLACE)); + return static_cast(AActor::StaticSpawn(RUNTIME_CLASS(T), DVector3(0, 0, 0), NO_REPLACE)); } inline PClassActor *PClass::FindActor(FName name) diff --git a/src/dobject.h b/src/dobject.h index ee2bfb5af..d043dfada 100644 --- a/src/dobject.h +++ b/src/dobject.h @@ -84,8 +84,7 @@ class DPillar; class PClassActor; #define RUNTIME_CLASS_CASTLESS(cls) (cls::RegistrationInfo.MyClass) // Passed a native class name, returns a PClass representing that class -#define RUNTIME_CLASS(cls) ((cls::MetaClass *)RUNTIME_CLASS_CASTLESS(cls)) // Like above, but returns the true type of the meta object -#define RUNTIME_TEMPLATE_CLASS(cls) ((typename cls::MetaClass *)RUNTIME_CLASS_CASTLESS(cls)) // RUNTIME_CLASS, but works with templated parameters on GCC +#define RUNTIME_CLASS(cls) ((typename cls::MetaClass *)RUNTIME_CLASS_CASTLESS(cls)) // Like above, but returns the true type of the meta object #define NATIVE_TYPE(object) (object->StaticType()) // Passed an object, returns the type of the C++ class representing the object // Enumerations for the meta classes created by ClassReg::RegisterClass() diff --git a/src/dthinker.h b/src/dthinker.h index c7a768ae3..da7eced7d 100644 --- a/src/dthinker.h +++ b/src/dthinker.h @@ -134,10 +134,10 @@ protected: template class TThinkerIterator : public FThinkerIterator { public: - TThinkerIterator (int statnum=MAX_STATNUM+1) : FThinkerIterator (RUNTIME_TEMPLATE_CLASS(T), statnum) + TThinkerIterator (int statnum=MAX_STATNUM+1) : FThinkerIterator (RUNTIME_CLASS(T), statnum) { } - TThinkerIterator (int statnum, DThinker *prev) : FThinkerIterator (RUNTIME_TEMPLATE_CLASS(T), statnum, prev) + TThinkerIterator (int statnum, DThinker *prev) : FThinkerIterator (RUNTIME_CLASS(T), statnum, prev) { } TThinkerIterator (const PClass *subclass, int statnum=MAX_STATNUM+1) : FThinkerIterator(subclass, statnum)