From 5e0ce969fe15c808e71c04618cd12729aa8ba830 Mon Sep 17 00:00:00 2001 From: rdb Date: Thu, 24 May 2018 14:30:08 +0200 Subject: [PATCH] Work around clang 3.1 compile error with static constexpr There is a bug in clang versions before 3.2 (including the one shipped with Xcode) that makes it give a "conflicting types" compile error when there is a static constexpr function defined outside the class. The way to work around this is either to remove one of the "static" or "constexpr" keywords, or to simply put the definition inline. See: https://stackoverflow.com/a/17494592/2135754 I would try and upgrade Xcode to version 5 to see if the problem is fixed, but the buildbot still runs OS X Lion (10.7) and the last version of Xcode that works on Lion is 4.6.3, so it seems easier to just apply these workarounds for now. --- dtool/src/dtoolbase/memoryHook.I | 9 ------ dtool/src/dtoolbase/memoryHook.h | 4 ++- dtool/src/dtoolbase/typeHandle.I | 19 ------------- dtool/src/dtoolbase/typeHandle.h | 4 +-- panda/src/pgraph/renderAttribRegistry.I | 13 --------- panda/src/pgraph/renderAttribRegistry.h | 2 +- panda/src/putil/bitArray.I | 38 ------------------------- panda/src/putil/bitArray.h | 6 ++-- panda/src/putil/bitMask.I | 31 +------------------- panda/src/putil/bitMask.h | 6 ++-- panda/src/putil/doubleBitMask.I | 31 +------------------- panda/src/putil/doubleBitMask.h | 6 ++-- panda/src/putil/updateSeq.I | 24 ---------------- panda/src/putil/updateSeq.h | 8 +++--- 14 files changed, 21 insertions(+), 180 deletions(-) diff --git a/dtool/src/dtoolbase/memoryHook.I b/dtool/src/dtoolbase/memoryHook.I index 055856f37b..cc4f972f6b 100644 --- a/dtool/src/dtoolbase/memoryHook.I +++ b/dtool/src/dtoolbase/memoryHook.I @@ -34,15 +34,6 @@ dec_heap(size_t size) { #endif // DO_MEMORY_USAGE } -/** - * Returns the global memory alignment. This is the number of bytes at which - * each allocated memory pointer will be aligned. - */ -constexpr size_t MemoryHook:: -get_memory_alignment() { - return MEMORY_HOOK_ALIGNMENT; -} - /** * Returns the operating system page size. This is the minimum granularity * required for calls to mmap_alloc(). Also see round_up_to_page_size(). diff --git a/dtool/src/dtoolbase/memoryHook.h b/dtool/src/dtoolbase/memoryHook.h index b5fceacd53..bb30e7f03d 100644 --- a/dtool/src/dtoolbase/memoryHook.h +++ b/dtool/src/dtoolbase/memoryHook.h @@ -52,7 +52,9 @@ public: bool heap_trim(size_t pad); - constexpr static size_t get_memory_alignment(); + constexpr static size_t get_memory_alignment() { + return MEMORY_HOOK_ALIGNMENT; + } virtual void *mmap_alloc(size_t size, bool allow_exec); virtual void mmap_free(void *ptr, size_t size); diff --git a/dtool/src/dtoolbase/typeHandle.I b/dtool/src/dtoolbase/typeHandle.I index bb7a737bf2..c63524c18c 100644 --- a/dtool/src/dtoolbase/typeHandle.I +++ b/dtool/src/dtoolbase/typeHandle.I @@ -191,14 +191,6 @@ output(ostream &out) const { out << get_name(); } -/** - * Returns a special zero-valued TypeHandle that is used to indicate no type. - */ -constexpr TypeHandle TypeHandle:: -none() { - return TypeHandle(0); -} - /** * TypeHandle::none() evaluates to false, everything else evaluates to true. */ @@ -207,17 +199,6 @@ operator bool () const { return (_index != 0); } -/** - * Creates a TypeHandle from a type index without error checking, for use by - * internal functions. - * - * See TypeRegistry::find_type_by_id(). - */ -constexpr TypeHandle TypeHandle:: -from_index(int index) { - return TypeHandle(index); -} - /** * Private constructor for initializing a TypeHandle from an index, used by * none() and by from_index(). diff --git a/dtool/src/dtoolbase/typeHandle.h b/dtool/src/dtoolbase/typeHandle.h index ed539e0619..b1b99c4ae0 100644 --- a/dtool/src/dtoolbase/typeHandle.h +++ b/dtool/src/dtoolbase/typeHandle.h @@ -129,7 +129,7 @@ PUBLISHED: INLINE int get_index() const; INLINE void output(ostream &out) const; - constexpr static TypeHandle none(); + constexpr static TypeHandle none() { return TypeHandle(0); } INLINE operator bool () const; MAKE_PROPERTY(index, get_index); @@ -142,7 +142,7 @@ public: void *reallocate_array(void *ptr, size_t size) RETURNS_ALIGNED(MEMORY_HOOK_ALIGNMENT); void deallocate_array(void *ptr); - constexpr static TypeHandle from_index(int index); + constexpr static TypeHandle from_index(int index) { return TypeHandle(index); } private: constexpr TypeHandle(int index); diff --git a/panda/src/pgraph/renderAttribRegistry.I b/panda/src/pgraph/renderAttribRegistry.I index fab7f22d24..5ad950dd4d 100644 --- a/panda/src/pgraph/renderAttribRegistry.I +++ b/panda/src/pgraph/renderAttribRegistry.I @@ -24,19 +24,6 @@ get_slot(TypeHandle type_handle) const { return _slots_by_type[(size_t)type_index]; } -/** - * Returns the maximum number that any slot number is allowed to grow. - * Actually, this number will be one higher than the highest possible slot - * number. This puts an upper bound on the number of RenderAttrib slots that - * may be allocated, and allows other code to define an array of slots. - * - * This number will not change during the lifetime of the application. - */ -constexpr int RenderAttribRegistry:: -get_max_slots() { - return _max_slots; -} - /** * Returns the number of RenderAttrib slots that have been allocated. This is * one more than the highest slot number in use. diff --git a/panda/src/pgraph/renderAttribRegistry.h b/panda/src/pgraph/renderAttribRegistry.h index ae47bd39a8..c7cf71b044 100644 --- a/panda/src/pgraph/renderAttribRegistry.h +++ b/panda/src/pgraph/renderAttribRegistry.h @@ -54,7 +54,7 @@ public: PUBLISHED: INLINE int get_slot(TypeHandle type_handle) const; - static constexpr int get_max_slots(); + static constexpr int get_max_slots() { return _max_slots; } INLINE int get_num_slots() const; INLINE TypeHandle get_slot_type(int slot) const; diff --git a/panda/src/putil/bitArray.I b/panda/src/putil/bitArray.I index 2a3341833d..605cf40a57 100644 --- a/panda/src/putil/bitArray.I +++ b/panda/src/putil/bitArray.I @@ -78,44 +78,6 @@ range(int low_bit, int size) { return result; } -/** - * Returns true if there is a maximum number of bits that may be stored in - * this structure, false otherwise. If this returns true, the number may be - * queried in get_max_num_bits(). - * - * This method always returns false. The BitArray has no maximum number of - * bits. This method is defined so generic programming algorithms can use - * BitMask or BitArray interchangeably. - */ -constexpr bool BitArray:: -has_max_num_bits() { - return false; -} - -/** - * If get_max_num_bits() returned true, this method may be called to return - * the maximum number of bits that may be stored in this structure. It is an - * error to call this if get_max_num_bits() return false. - * - * It is always an error to call this method. The BitArray has no maximum - * number of bits. This method is defined so generic programming algorithms - * can use BitMask or BitArray interchangeably. - */ -constexpr int BitArray:: -get_max_num_bits() { - return INT_MAX; -} - -/** - * Returns the number of bits stored per word internally. This is of interest - * only in that it limits the maximum number of bits that may be queried or - * set at once by extract() and store(). - */ -constexpr int BitArray:: -get_num_bits_per_word() { - return num_bits_per_word; -} - /** * Returns the current number of possibly different bits in this array. There * are actually an infinite number of bits, but every bit higher than this bit diff --git a/panda/src/putil/bitArray.h b/panda/src/putil/bitArray.h index 42070ad3f8..bb00dea0d7 100644 --- a/panda/src/putil/bitArray.h +++ b/panda/src/putil/bitArray.h @@ -54,10 +54,10 @@ PUBLISHED: INLINE static BitArray bit(int index); INLINE static BitArray range(int low_bit, int size); - constexpr static bool has_max_num_bits(); - constexpr static int get_max_num_bits(); + constexpr static bool has_max_num_bits() { return false; } + constexpr static int get_max_num_bits() { return INT_MAX; } - constexpr static int get_num_bits_per_word(); + constexpr static int get_num_bits_per_word() { return num_bits_per_word; } INLINE size_t get_num_bits() const; INLINE bool get_bit(int index) const; INLINE void set_bit(int index); diff --git a/panda/src/putil/bitMask.I b/panda/src/putil/bitMask.I index 837101a961..fa1073ad4b 100644 --- a/panda/src/putil/bitMask.I +++ b/panda/src/putil/bitMask.I @@ -101,41 +101,12 @@ range(int low_bit, int size) { return result; } -/** - * Returns true if there is a maximum number of bits that may be stored in - * this structure, false otherwise. If this returns true, the number may be - * queried in get_max_num_bits(). - * - * This method always returns true. This method is defined so generic - * programming algorithms can use BitMask or BitArray interchangeably. - */ -template -constexpr bool BitMask:: -has_max_num_bits() { - return true; -} - -/** - * If get_max_num_bits() returned true, this method may be called to return - * the maximum number of bits that may be stored in this structure. It is an - * error to call this if get_max_num_bits() return false. - * - * It is never an error to call this method. This returns the same thing as - * get_num_bits(). This method is defined so generic programming algorithms - * can use BitMask or BitArray interchangeably. - */ -template -constexpr int BitMask:: -get_max_num_bits() { - return num_bits; -} - /** * Returns the number of bits available to set in the bitmask. */ template constexpr int BitMask:: -get_num_bits() { +get_num_bits() const { return num_bits; } diff --git a/panda/src/putil/bitMask.h b/panda/src/putil/bitMask.h index 589c4dd73c..3d73089b50 100644 --- a/panda/src/putil/bitMask.h +++ b/panda/src/putil/bitMask.h @@ -45,10 +45,10 @@ PUBLISHED: INLINE static BitMask bit(int index); INLINE static BitMask range(int low_bit, int size); - constexpr static bool has_max_num_bits(); - constexpr static int get_max_num_bits(); + constexpr static bool has_max_num_bits() { return true; } + constexpr static int get_max_num_bits() { return num_bits; } - constexpr static int get_num_bits(); + constexpr int get_num_bits() const; INLINE bool get_bit(int index) const; INLINE void set_bit(int index); INLINE void clear_bit(int index); diff --git a/panda/src/putil/doubleBitMask.I b/panda/src/putil/doubleBitMask.I index 0b08768229..0768263afe 100644 --- a/panda/src/putil/doubleBitMask.I +++ b/panda/src/putil/doubleBitMask.I @@ -119,41 +119,12 @@ INLINE DoubleBitMask:: ~DoubleBitMask() { } -/** - * Returns true if there is a maximum number of bits that may be stored in - * this structure, false otherwise. If this returns true, the number may be - * queried in get_max_num_bits(). - * - * This method always returns true. This method is defined so generic - * programming algorithms can use DoubleBitMask or BitArray interchangeably. - */ -template -constexpr bool DoubleBitMask:: -has_max_num_bits() { - return true; -} - -/** - * If get_max_num_bits() returned true, this method may be called to return - * the maximum number of bits that may be stored in this structure. It is an - * error to call this if get_max_num_bits() return false. - * - * It is never an error to call this method. This returns the same thing as - * get_num_bits(). This method is defined so generic programming algorithms - * can use DoubleBitMask or BitArray interchangeably. - */ -template -constexpr int DoubleBitMask:: -get_max_num_bits() { - return num_bits; -} - /** * Returns the number of bits available to set in the doubleBitMask. */ template constexpr int DoubleBitMask:: -get_num_bits() { +get_num_bits() const { return num_bits; } diff --git a/panda/src/putil/doubleBitMask.h b/panda/src/putil/doubleBitMask.h index 472a1ddc3f..6c32cd0122 100644 --- a/panda/src/putil/doubleBitMask.h +++ b/panda/src/putil/doubleBitMask.h @@ -49,10 +49,10 @@ PUBLISHED: INLINE ~DoubleBitMask(); - constexpr static bool has_max_num_bits(); - constexpr static int get_max_num_bits(); + constexpr static bool has_max_num_bits() {return true;} + constexpr static int get_max_num_bits() {return num_bits;} - constexpr static int get_num_bits(); + constexpr int get_num_bits() const; INLINE bool get_bit(int index) const; INLINE void set_bit(int index); INLINE void clear_bit(int index); diff --git a/panda/src/putil/updateSeq.I b/panda/src/putil/updateSeq.I index 1df2577c35..0083c98bca 100644 --- a/panda/src/putil/updateSeq.I +++ b/panda/src/putil/updateSeq.I @@ -25,30 +25,6 @@ constexpr UpdateSeq:: UpdateSeq() : _seq((unsigned int)SC_initial) { } -/** - * Returns an UpdateSeq in the 'initial' state. - */ -constexpr UpdateSeq UpdateSeq:: -initial() { - return UpdateSeq((unsigned int)SC_initial); -} - -/** - * Returns an UpdateSeq in the 'old' state. - */ -constexpr UpdateSeq UpdateSeq:: -old() { - return UpdateSeq((unsigned int)SC_old); -} - -/** - * Returns an UpdateSeq in the 'fresh' state. - */ -constexpr UpdateSeq UpdateSeq:: -fresh() { - return UpdateSeq((unsigned int)SC_fresh); -} - /** * */ diff --git a/panda/src/putil/updateSeq.h b/panda/src/putil/updateSeq.h index 4a982df279..bdddadde6e 100644 --- a/panda/src/putil/updateSeq.h +++ b/panda/src/putil/updateSeq.h @@ -40,9 +40,9 @@ private: PUBLISHED: constexpr UpdateSeq(); - constexpr static UpdateSeq initial(); - constexpr static UpdateSeq old(); - constexpr static UpdateSeq fresh(); + constexpr static UpdateSeq initial() { return UpdateSeq(SC_initial); } + constexpr static UpdateSeq old() { return UpdateSeq(SC_old); } + constexpr static UpdateSeq fresh() { return UpdateSeq(SC_fresh); } INLINE UpdateSeq(const UpdateSeq ©); constexpr UpdateSeq(const UpdateSeq &&from) noexcept; @@ -76,7 +76,7 @@ private: INLINE static bool priv_le(AtomicAdjust::Integer a, AtomicAdjust::Integer b); private: - enum SpecialCases { + enum SpecialCases : unsigned int { SC_initial = 0, SC_old = 1, SC_fresh = ~(unsigned int)0,