[llvm] r264541 - isPodLike: more precise

JF Bastien via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 27 13:38:14 PDT 2016


FYI dblaikie, we'll see if this one works :-)

On Sun, Mar 27, 2016 at 1:32 PM, JF Bastien via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> Author: jfb
> Date: Sun Mar 27 15:32:21 2016
> New Revision: 264541
>
> URL: http://llvm.org/viewvc/llvm-project?rev=264541&view=rev
> Log:
> isPodLike: more precise
>
> I tried to use isPodLike in:
>   http://reviews.llvm.org/D18483
>
> That failed because !is_class is too strict on platforms which don't yet
> have is_trivially_copyable. This update tries to make isPodLike smarter
> for platforms which don't have is_trivially_copyable, and AFAICT it
> Should Just Work on all of them. I'll revert if the bots disagree with
> me.
>
> I'll also rename isPodLike to isTriviallyCopyable if this all works out,
> since that's what the standard calls it now and one day we'll be rid of
> isPodLike.
>
> Modified:
>     llvm/trunk/include/llvm/Support/type_traits.h
>
> Modified: llvm/trunk/include/llvm/Support/type_traits.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/type_traits.h?rev=264541&r1=264540&r2=264541&view=diff
>
> ==============================================================================
> --- llvm/trunk/include/llvm/Support/type_traits.h (original)
> +++ llvm/trunk/include/llvm/Support/type_traits.h Sun Mar 27 15:32:21 2016
> @@ -24,12 +24,11 @@
>
>  namespace llvm {
>
> -/// isPodLike - This is a type trait that is used to determine whether a
> given
> -/// type can be copied around with memcpy instead of running ctors etc.
> -template <typename T>
> -struct isPodLike {
> -  // std::is_trivially_copyable is available in libc++ with clang,
> libstdc++
> -  // that comes with GCC 5.
> +/// Type trait used to determine whether a given type can be copied
> around with
> +/// memcpy instead of running ctors.
> +template <typename T> struct isPodLike {
> +// std::is_trivially_copyable is available in libc++ with clang, libstdc++
> +// that comes with GCC 5.
>  #if (__has_feature(is_trivially_copyable) && defined(_LIBCPP_VERSION))
> ||      \
>      (defined(__GNUC__) && __GNUC__ >= 5)
>    // If the compiler supports the is_trivially_copyable trait use it, as
> it
> @@ -40,10 +39,15 @@ struct isPodLike {
>    // don't know if the standard library does. This is the case for clang
> in
>    // conjunction with libstdc++ from GCC 4.x.
>    static const bool value = __is_trivially_copyable(T);
> +#elif defined(__GNUC__)
> +  // Fallback to ye olden compiler intrinsic, which isn't as accurate as
> the new
> +  // one but more widely supported.
> +  static const bool value = __has_trivial_copy(T);
>  #else
> -  // If we don't know anything else, we can (at least) assume that all
> non-class
> -  // types are PODs.
> -  static const bool value = !std::is_class<T>::value;
> +  // If we really don't know anything else is_pod will do, is widely
> supported,
> +  // but is too strict (e.g. a user-defined ctor doesn't prevent trivial
> copy
> +  // but prevents POD-ness).
> +  static const bool value = std::is_pod<T>::value;
>  #endif
>  };
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160327/dbbdc55e/attachment.html>


More information about the llvm-commits mailing list