From 0fa54bc56a74ada4af222e9750c6e13adfc4915d Mon Sep 17 00:00:00 2001 From: janwas Date: Mon, 10 Oct 2011 20:08:04 +0000 Subject: [PATCH] fix compile error due to GCC restriction. thanks to daniel.santos for reporting and alex for creating the ticket/notifying me. fixes #992 [heh, the amount of comments are proportional to the trouble caused by this code :S ran into VC++ compile errors when __declspec came after void* return type *sigh*] This was SVN commit r10385. --- source/lib/allocators/aligned_allocator.h | 14 ++++++------ source/lib/allocators/headerless.cpp | 4 ++-- source/lib/allocators/headerless.h | 2 +- source/lib/allocators/unique_range.cpp | 2 +- source/lib/allocators/unique_range.h | 2 +- source/lib/code_annotation.h | 28 ++++++++++++++++++----- 6 files changed, 34 insertions(+), 18 deletions(-) diff --git a/source/lib/allocators/aligned_allocator.h b/source/lib/allocators/aligned_allocator.h index 4c5598482f..1264c2a9b5 100644 --- a/source/lib/allocators/aligned_allocator.h +++ b/source/lib/allocators/aligned_allocator.h @@ -81,24 +81,24 @@ public: return &value; } - AlignedAllocator() NOTHROW + NOTHROW_DEFINE AlignedAllocator() { } - AlignedAllocator(const AlignedAllocator&) NOTHROW + NOTHROW_DEFINE AlignedAllocator(const AlignedAllocator&) { } template - AlignedAllocator (const AlignedAllocator&) NOTHROW + NOTHROW_DEFINE AlignedAllocator (const AlignedAllocator&) { } - ~AlignedAllocator() NOTHROW + NOTHROW_DEFINE ~AlignedAllocator() { } - size_type max_size() const NOTHROW + NOTHROW_DEFINE size_type max_size() const { // maximum number of *elements* that can be allocated return std::numeric_limits::max() / sizeof(T); @@ -133,13 +133,13 @@ public: // indicate that all specializations of this allocator are interchangeable template -bool operator==(const AlignedAllocator&, const AlignedAllocator&) NOTHROW +NOTHROW_DEFINE bool operator==(const AlignedAllocator&, const AlignedAllocator&) { return true; } template -bool operator!=(const AlignedAllocator&, const AlignedAllocator&) NOTHROW +NOTHROW_DEFINE bool operator!=(const AlignedAllocator&, const AlignedAllocator&) { return false; } diff --git a/source/lib/allocators/headerless.cpp b/source/lib/allocators/headerless.cpp index 5c3a461e6b..7b1f738e0a 100644 --- a/source/lib/allocators/headerless.cpp +++ b/source/lib/allocators/headerless.cpp @@ -627,7 +627,7 @@ public: Validate(); } - void* Allocate(size_t size) NOTHROW + NOTHROW_DEFINE void* Allocate(size_t size) { ENSURE(IsValidSize(size)); Validate(); @@ -754,7 +754,7 @@ void HeaderlessAllocator::Reset() return impl->Reset(); } -void* HeaderlessAllocator::Allocate(size_t size) NOTHROW +NOTHROW_DEFINE void* HeaderlessAllocator::Allocate(size_t size) { return impl->Allocate(size); } diff --git a/source/lib/allocators/headerless.h b/source/lib/allocators/headerless.h index d1850e5732..6f7893c9c7 100644 --- a/source/lib/allocators/headerless.h +++ b/source/lib/allocators/headerless.h @@ -76,7 +76,7 @@ public: * (this allocator is designed for requests on the order of several KiB) * @return allocated memory or 0 if the pool is too fragmented or full. **/ - void* Allocate(size_t size) NOTHROW; + NOTHROW_DECLARE void* Allocate(size_t size); /** * deallocate memory. diff --git a/source/lib/allocators/unique_range.cpp b/source/lib/allocators/unique_range.cpp index a661f247ed..6755fa5e08 100644 --- a/source/lib/allocators/unique_range.cpp +++ b/source/lib/allocators/unique_range.cpp @@ -50,7 +50,7 @@ void RegisterUniqueRangeDeleter(UniqueRangeDeleter deleter, volatile IdxDeleter* } -void CallUniqueRangeDeleter(void* pointer, size_t size, IdxDeleter idxDeleter) NOTHROW +NOTHROW_DEFINE void CallUniqueRangeDeleter(void* pointer, size_t size, IdxDeleter idxDeleter) { ASSERT(idxDeleter < numDeleters); // (some deleters do not tolerate null pointers) diff --git a/source/lib/allocators/unique_range.h b/source/lib/allocators/unique_range.h index 1b669ac0b2..c6b543e326 100644 --- a/source/lib/allocators/unique_range.h +++ b/source/lib/allocators/unique_range.h @@ -43,7 +43,7 @@ typedef void (*UniqueRangeDeleter)(void* pointer, size_t size); **/ LIB_API void RegisterUniqueRangeDeleter(UniqueRangeDeleter deleter, volatile IdxDeleter* idxDeleter); -LIB_API void CallUniqueRangeDeleter(void* pointer, size_t size, IdxDeleter idxDeleter) NOTHROW; +LIB_API NOTHROW_DECLARE void CallUniqueRangeDeleter(void* pointer, size_t size, IdxDeleter idxDeleter); // unfortunately, unique_ptr allows constructing without a custom deleter. to ensure callers can diff --git a/source/lib/code_annotation.h b/source/lib/code_annotation.h index 5383364c94..e07e0acc10 100644 --- a/source/lib/code_annotation.h +++ b/source/lib/code_annotation.h @@ -58,16 +58,32 @@ /** - * void function() NOTHROW - indicate the function will not - * throw any synchronous exceptions, thus hopefully generating - * smaller and more efficient code. + * indicate a function will not throw any synchronous exceptions, + * thus hopefully generating smaller and more efficient code. + * + * must be placed BEFORE return types because "The [VC++] compiler + * ignores, without warning, any __declspec keywords placed after *". + * such syntax is apparently also legal in GCC, per the example + * "__attribute__((noreturn)) void d0 (void)". + * + * example: + * NOTHROW_DECLARE void function(); + * NOTHROW_DEFINE void function() {} **/ #if GCC_VERSION >= 303 -# define NOTHROW __attribute__((nothrow)) +# define NOTHROW_DECLARE __attribute__((nothrow)) +# define NOTHROW_DEFINE // not supported for definitions #elif MSC_VERSION -# define NOTHROW throw() // special meaning, equivalent to __declspec(nothrow) +// Kevin Frei, 2006-03-23: "I work on the Visual C++ compiler team, +// and agree completely with Paul Parks: don't use throw(), because +// there's a chance that we'll eventually implement it according to the standard". +# define NOTHROW_DECLARE __declspec(nothrow) +# define NOTHROW_DEFINE __declspec(nothrow) #else -# define NOTHROW // throw() might result in ADDITIONAL checks +// don't use throw() because it might result in ADDITIONAL checks +// (the standard mandates calling unexpected()) +# define NOTHROW_DECLARE +# define NOTHROW_DEFINE #endif