RFR: 8067790: Better support for native implementations of Atomic::cmpxchg

Kim Barrett kim.barrett at oracle.com
Thu Jan 1 18:32:37 UTC 2015


On Jan 1, 2015, at 2:42 AM, Kim Barrett <kim.barrett at oracle.com> wrote:
> 
> // Metafunction whose nested value member is true if T is defined
> // (complete), and false if T is incomplete.  T must be a non-cv
> // qualified class type.  If T is incomplete at the point where this
> // metafunction is invoked, it must never be defined elsewhere in the
> // program.
> template<typename T>
> class IsClassDefined {
>  typedef char yes[1];
>  typedef char no[2];
> 
>  template<typename U>
>  static typename EnableIf<sizeof(U) == sizeof(U), yes>::type & check(U*);

Change "sizeof(U) == sizeof(U)” => "sizeof(U) != 0”.

>  static no& check(...);
> 
> public:
>  static const bool value = sizeof(check((T*)0)) == sizeof(yes);
> };
> 

Further (web) research indicates that perhaps some compilers implement
sizeof of an incomplete type as returning 0, rather than as an error.

Strictly speaking, applying sizeof to an incomplete type results in undefined
behavior, but this technique is in quite wide-spread use.



More information about the hotspot-dev mailing list