[cfe-dev] #ifdef __clang__ guard in AllocatorBase

Richard Smith via cfe-dev cfe-dev at lists.llvm.org
Wed Feb 3 16:15:58 PST 2016


I would guess it's the pointer to member, not the static_assert. MSVC has
significant problems with casts from the address of a member function to a
pointer-to-member type (either a type mismatch due to a calling convention
attribute or a failure to resolve overloaded functions properly, I don't
remember). We do something similar to this in Clang's RecursiveASTVisitor,
and it took a number of iterations to find a form that all of our buildbots
were happy with.

On Wed, Feb 3, 2016 at 10:42 AM, David Blaikie via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> possible that static_assert isn't supported on some of the compilers we
> support, or didn't at some point. I'd check the commit history and if the
> reason cited (if there is one) doesn't apply anymore, just remove it.
>
> On Wed, Feb 3, 2016 at 10:16 AM, <Alexander G. Riccio> via cfe-dev <
> cfe-dev at lists.llvm.org> wrote:
>
>> In Allocator.h, there are two static_asserts that are guarded by an #ifdef
>> __clang__. What's up with that? Shouldn't non __clang__ environments be
>> able to do this? Surely there's a better way to check for overloads?
>>
>> The two static_asserts in question:
>>
>>   /// \brief Allocate \a Size bytes of \a Alignment aligned memory. This method
>>   /// must be implemented by \c DerivedT.
>>   void *Allocate(size_t Size, size_t Alignment) {#ifdef __clang__
>>     static_assert(static_cast<void *(AllocatorBase::*)(size_t, size_t)>(
>>                       &AllocatorBase::Allocate) !=
>>                       static_cast<void *(DerivedT::*)(size_t, size_t)>(
>>                           &DerivedT::Allocate),
>>                   "Class derives from AllocatorBase without implementing the "
>>                   "core Allocate(size_t, size_t) overload!");#endif
>>     return static_cast<DerivedT *>(this)->Allocate(Size, Alignment);
>>   }
>>
>>   /// \brief Deallocate \a Ptr to \a Size bytes of memory allocated by this
>>   /// allocator.
>>   void Deallocate(const void *Ptr, size_t Size) {#ifdef __clang__
>>     static_assert(static_cast<void (AllocatorBase::*)(const void *, size_t)>(
>>                       &AllocatorBase::Deallocate) !=
>>                       static_cast<void (DerivedT::*)(const void *, size_t)>(
>>                           &DerivedT::Deallocate),
>>                   "Class derives from AllocatorBase without implementing the "
>>                   "core Deallocate(void *) overload!");#endif
>>     return static_cast<DerivedT *>(this)->Deallocate(Ptr, Size);
>>   }
>>
>>
>>
>> Sincerely,
>> Alexander Riccio
>> --
>> "Change the world or go home."
>> about.me/ariccio
>>
>> <http://about.me/ariccio>
>> If left to my own devices, I will build more.
>>>>
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>>
>>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160203/c5c87c76/attachment.html>


More information about the cfe-dev mailing list