<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Thanks for the review Richard.  Would you like me to revert, or can I just make these changes in a new patch?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> Richard Smith [mailto:richard@metafoo.co.uk]
<br>
<b>Sent:</b> Thursday, October 26, 2017 9:50 AM<br>
<b>To:</b> Keane, Erich <erich.keane@intel.com><br>
<b>Cc:</b> cfe-commits <cfe-commits@lists.llvm.org><br>
<b>Subject:</b> Re: r316518 - mplement __has_unique_object_representations<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<div>
<div>
<p class="MsoNormal">On 24 Oct 2017 14:32, "Erich Keane via cfe-commits" <<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<o:p></o:p></p>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal">Author: erichkeane<br>
Date: Tue Oct 24 14:31:50 2017<br>
New Revision: 316518<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=316518&view=rev" target="_blank">
http://llvm.org/viewvc/llvm-project?rev=316518&view=rev</a><br>
Log:<br>
mplement __has_unique_object_representations<br>
<br>
A helper builtin to facilitate implementing the<br>
std::has_unique_object_representations type trait.<br>
<br>
Requested here: <a href="https://bugs.llvm.org/show_bug.cgi?id=34942" target="_blank">
https://bugs.llvm.org/show_bug.cgi?id=34942</a><br>
Also already exists in GCC and MSVC.<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D39064" target="_blank">
https://reviews.llvm.org/D39064</a><br>
<br>
Modified:<br>
    cfe/trunk/include/clang/AST/Type.h<br>
    cfe/trunk/include/clang/Basic/TokenKinds.def<br>
    cfe/trunk/include/clang/Basic/TypeTraits.h<br>
    cfe/trunk/lib/AST/Type.cpp<br>
    cfe/trunk/lib/Parse/ParseExpr.cpp<br>
    cfe/trunk/lib/Sema/SemaExprCXX.cpp<br>
    cfe/trunk/test/SemaCXX/type-traits.cpp<br>
<br>
Modified: cfe/trunk/include/clang/AST/Type.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=316518&r1=316517&r2=316518&view=diff" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=316518&r1=316517&r2=316518&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/AST/Type.h (original)<br>
+++ cfe/trunk/include/clang/AST/Type.h Tue Oct 24 14:31:50 2017<br>
@@ -770,6 +770,10 @@ public:<br>
   /// Return true if this is a trivially copyable type (C++0x [basic.types]p9)<br>
   bool isTriviallyCopyableType(const ASTContext &Context) const;<br>
<br>
+  /// Return true if this has unique object representations according to (C++17<br>
+  /// [meta.unary.prop]p9)<br>
+  bool hasUniqueObjectRepresentations(const ASTContext &Context) const;<o:p></o:p></p>
</blockquote>
</div>
</div>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">I think this would make more sense as a member of ASTContext. The Type object generally doesn't know or care about its representation.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<div>
<div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal">+<br>
   // Don't promise in the API that anything besides 'const' can be<br>
   // easily added.<br>
<br>
@@ -1114,6 +1118,8 @@ public:<br>
   QualType getAtomicUnqualifiedType() const;<br>
<br>
 private:<br>
+  bool unionHasUniqueObjectRepresentations(const ASTContext& Context) const;<br>
+  bool structHasUniqueObjectRepresentations(const ASTContext& Context) const;<br>
   // These methods are implemented in a separate translation unit;<br>
   // "static"-ize them to avoid creating temporary QualTypes in the<br>
   // caller.<br>
<br>
Modified: cfe/trunk/include/clang/Basic/TokenKinds.def<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TokenKinds.def?rev=316518&r1=316517&r2=316518&view=diff" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TokenKinds.def?rev=316518&r1=316517&r2=316518&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Basic/TokenKinds.def (original)<br>
+++ cfe/trunk/include/clang/Basic/TokenKinds.def Tue Oct 24 14:31:50 2017<br>
@@ -455,6 +455,8 @@ TYPE_TRAIT_1(__is_pod, IsPOD, KEYCXX)<br>
 TYPE_TRAIT_1(__is_polymorphic, IsPolymorphic, KEYCXX)<br>
 TYPE_TRAIT_1(__is_trivial, IsTrivial, KEYCXX)<br>
 TYPE_TRAIT_1(__is_union, IsUnion, KEYCXX)<br>
+TYPE_TRAIT_1(__has_unique_object_representations,<br>
+             HasUniqueObjectRepresentations, KEYCXX)<br>
<br>
 // Clang-only C++ Type Traits<br>
 TYPE_TRAIT_N(__is_trivially_constructible, IsTriviallyConstructible, KEYCXX)<br>
<br>
Modified: cfe/trunk/include/clang/Basic/TypeTraits.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TypeTraits.h?rev=316518&r1=316517&r2=316518&view=diff" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TypeTraits.h?rev=316518&r1=316517&r2=316518&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Basic/TypeTraits.h (original)<br>
+++ cfe/trunk/include/clang/Basic/TypeTraits.h Tue Oct 24 14:31:50 2017<br>
@@ -70,7 +70,8 @@ namespace clang {<br>
     UTT_IsUnsigned,<br>
     UTT_IsVoid,<br>
     UTT_IsVolatile,<br>
-    UTT_Last = UTT_IsVolatile,<br>
+    UTT_HasUniqueObjectRepresentations,<br>
+    UTT_Last = UTT_HasUniqueObjectRepresentations,<br>
     BTT_IsBaseOf,<br>
     BTT_IsConvertible,<br>
     BTT_IsConvertibleTo,<br>
<br>
Modified: cfe/trunk/lib/AST/Type.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=316518&r1=316517&r2=316518&view=diff" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=316518&r1=316517&r2=316518&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/AST/Type.cpp (original)<br>
+++ cfe/trunk/lib/AST/Type.cpp Tue Oct 24 14:31:50 2017<br>
@@ -2166,6 +2166,152 @@ bool QualType::isTriviallyCopyableType(c<br>
   return false;<br>
 }<br>
<br>
+bool QualType::unionHasUniqueObjectRepresentations(<br>
+    const ASTContext &Context) const {<br>
+  assert((*this)->isUnionType() && "must be union type");<br>
+  CharUnits UnionSize = Context.getTypeSizeInChars(*this);<br>
+  const RecordDecl *Union = getTypePtr()->getAs<RecordType>()->getDecl();<br>
+<br>
+  for (const auto *Field : Union->fields()) {<br>
+    if (!Field->getType().hasUniqueObjectRepresentations(Context))<br>
+      return false;<br>
+    CharUnits FieldSize = Context.getTypeSizeInChars(Field->getType());<br>
+    if (FieldSize != UnionSize)<br>
+      return false;<br>
+  }<br>
+  return true;<br>
+}<br>
+<br>
+bool isStructEmpty(QualType Ty) {<br>
+  assert(Ty.getTypePtr()->isStructureOrClassType() &&<br>
+         "Must be struct or class");<br>
+  const RecordDecl *RD = Ty.getTypePtr()->getAs<RecordType>()->getDecl();<br>
+<br>
+  if (!RD->field_empty())<br>
+    return false;<br>
+<br>
+  if (const CXXRecordDecl *ClassDecl = dyn_cast<CXXRecordDecl>(RD)) {<br>
+    return ClassDecl->isEmpty();<br>
+  }<br>
+<br>
+  return true;<br>
+}<br>
+<br>
+bool QualType::structHasUniqueObjectRepresentations(<br>
+    const ASTContext &Context) const {<br>
+  assert((*this)->isStructureOrClassType() && "Must be struct or class");<br>
+  const RecordDecl *RD = getTypePtr()->getAs<RecordType>()->getDecl();<br>
+<br>
+  if (isStructEmpty(*this))<br>
+    return false;<br>
+<br>
+  // Check base types.<br>
+  CharUnits BaseSize{};<br>
+  if (const CXXRecordDecl *ClassDecl = dyn_cast<CXXRecordDecl>(RD)) {<br>
+    for (const auto Base : ClassDecl->bases()) {<br>
+      if (Base.isVirtual())<br>
+        return false;<o:p></o:p></p>
</blockquote>
</div>
</div>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Hmm, are there any cases in which we might want to guarantee the vptr is identical across all instances?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<div>
<div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal">+<br>
+      // Empty bases are permitted, otherwise ensure base has unique<br>
+      // representation. Also, Empty Base Optimization means that an<br>
+      // Empty base takes up 0 size.<o:p></o:p></p>
</blockquote>
</div>
</div>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">This seems really fragile to me. Empty bases may or may not occupy storage. But that's beside the point -- empty bases are just a special case of bases with tail padding, which are not properly handled here.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">I really think you should be walking the record layout rather than trying to determine this from sizes alone.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<div>
<div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal">+      if (!isStructEmpty(Base.getType())) {<br>
+        if (!Base.getType().structHasUniqueObjectRepresentations(Context))<br>
+          return false;<br>
+        BaseSize += Context.getTypeSizeInChars(Base.getType());<br>
+      }<br>
+    }<br>
+  }<br>
+<br>
+  CharUnits StructSize = Context.getTypeSizeInChars(*this);<br>
+<br>
+  // This struct obviously has bases that keep it from being 'empty', so<br>
+  // checking fields is no longer required.  Ensure that the struct size<br>
+  // is the sum of the bases.<br>
+  if (RD->field_empty())<br>
+    return StructSize == BaseSize;<br>
+  ;<o:p></o:p></p>
</blockquote>
</div>
</div>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Stray semicolon?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<div>
<div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal">+<br>
+  CharUnits CurOffset =<br>
+      Context.toCharUnitsFromBits(Context.getFieldOffset(*RD->field_begin()));<br>
+<br>
+  // If the first field isn't at the sum of the size of the bases, there<br>
+  // is padding somewhere.<br>
+  if (BaseSize != CurOffset)<br>
+    return false;<br>
+<br>
+  for (const auto *Field : RD->fields()) {<br>
+    if (!Field->getType().hasUniqueObjectRepresentations(Context))<br>
+      return false;<br>
+    CharUnits FieldSize = Context.getTypeSizeInChars(Field->getType());<br>
+    CharUnits FieldOffset =<br>
+        Context.toCharUnitsFromBits(Context.getFieldOffset(Field));<br>
+    // Has padding between fields.<br>
+    if (FieldOffset != CurOffset)<br>
+      return false;<br>
+    CurOffset += FieldSize;<br>
+  }<br>
+  // Check for tail padding.<br>
+  return CurOffset == StructSize;<br>
+}<br>
+<br>
+bool QualType::hasUniqueObjectRepresentations(const ASTContext &Context) const {<br>
+  // C++17 [meta.unary.prop]:<br>
+  //   The predicate condition for a template specialization<br>
+  //   has_unique_object_representations<T> shall be<br>
+  //   satisfied if and only if:<br>
+  //     (9.1) â€” T is trivially copyable, and<br>
+  //     (9.2) â€” any two objects of type T with the same value have the same<br>
+  //     object representation, where two objects<br>
+  //   of array or non-union class type are considered to have the same value<br>
+  //   if their respective sequences of<br>
+  //   direct subobjects have the same values, and two objects of union type<br>
+  //   are considered to have the same<br>
+  //   value if they have the same active member and the corresponding members<br>
+  //   have the same value.<br>
+  //   The set of scalar types for which this condition holds is<br>
+  //   implementation-defined. [ Note: If a type has padding<br>
+  //   bits, the condition does not hold; otherwise, the condition holds true<br>
+  //   for unsigned integral types. â€” end<br>
+  //   note ]<br>
+  if (isNull())<br>
+    return false;<br>
+<br>
+  // Arrays are unique only if their element type is unique.<br>
+  if ((*this)->isArrayType())<br>
+    return Context.getBaseElementType(*this).hasUniqueObjectRepresentations(<br>
+        Context);<o:p></o:p></p>
</blockquote>
</div>
</div>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">I don't think this is correct. As a weird GNU behaviour, we can have, say, a type with size 3 and alignment 4 (via an alignment attribute on a typedef). An array of 1 such element has size 4, and has padding even if its element type does
 not.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<div>
<div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal">+<br>
+  // (9.1) â€” T is trivially copyable, and<br>
+  if (!isTriviallyCopyableType(Context))<br>
+    return false;<br>
+<br>
+  // Functions are not unique.<br>
+  if ((*this)->isFunctionType())<br>
+    return false;<br>
+<br>
+  // All integrals and enums are unique!<br>
+  if ((*this)->isIntegralOrEnumerationType())<br>
+    return true;<br>
+<br>
+  // All pointers are unique, since they're just integrals.<o:p></o:p></p>
</blockquote>
</div>
</div>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">The second half of this comment doesn't seem right to me. They may be represented as sequences of bits, but that doesn't make them integral.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<div>
<div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal">+  if ((*this)->isPointerType() || (*this)->isMemberPointerType())<br>
+    return true;<br>
+<br>
+  if ((*this)->isRecordType()) {<br>
+    const RecordDecl *Record = getTypePtr()->getAs<RecordType>()->getDecl();<br>
+<br>
+    // Lambda types are not unique, so exclude them immediately.<o:p></o:p></p>
</blockquote>
</div>
</div>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Why?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<div>
<div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal">+    if (Record->isLambda())<br>
+      return false;<br>
+<br>
+    if (Record->isUnion())<br>
+      return unionHasUniqueObjectRepresentations(Context);<br>
+    return structHasUniqueObjectRepresentations(Context);<o:p></o:p></p>
</blockquote>
</div>
</div>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Making these members of QualType seems counterproductive. You already have the Record here; it'd be better to make these file-static and pass that in.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<div>
<div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal">+  }<br>
+  return false;<br>
+}<br>
+<br>
 bool QualType::isNonWeakInMRRWithObjCWeak(const ASTContext &Context) const {<br>
   return !Context.getLangOpts().ObjCAutoRefCount &&<br>
          Context.getLangOpts().ObjCWeak &&<br>
<br>
Modified: cfe/trunk/lib/Parse/ParseExpr.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=316518&r1=316517&r2=316518&view=diff" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=316518&r1=316517&r2=316518&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)<br>
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Tue Oct 24 14:31:50 2017<br>
@@ -716,6 +716,7 @@ class CastExpressionIdValidator : public<br>
 ///                   '__is_sealed'                           [MS]<br>
 ///                   '__is_trivial'<br>
 ///                   '__is_union'<br>
+///                   '__has_unique_object_representations'<br>
 ///<br>
 /// [Clang] unary-type-trait:<br>
 ///                   '__is_aggregate'<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=316518&r1=316517&r2=316518&view=diff" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=316518&r1=316517&r2=316518&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Tue Oct 24 14:31:50 2017<br>
@@ -4175,6 +4175,7 @@ static bool CheckUnaryTypeTraitTypeCompl<br>
   case UTT_IsDestructible:<br>
   case UTT_IsNothrowDestructible:<br>
   case UTT_IsTriviallyDestructible:<br>
+  case UTT_HasUniqueObjectRepresentations:<br>
     if (ArgTy->isIncompleteArrayType() || ArgTy->isVoidType())<br>
       return true;<br>
<br>
@@ -4614,6 +4615,8 @@ static bool EvaluateUnaryTypeTrait(Sema<br>
     //   Returns True if and only if T is a complete type at the point of the<br>
     //   function call.<br>
     return !T->isIncompleteType();<br>
+  case UTT_HasUniqueObjectRepresentations:<br>
+    return T.hasUniqueObjectRepresentations(C);<br>
   }<br>
 }<br>
<br>
<br>
Modified: cfe/trunk/test/SemaCXX/type-traits.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/type-traits.cpp?rev=316518&r1=316517&r2=316518&view=diff" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/type-traits.cpp?rev=316518&r1=316517&r2=316518&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/SemaCXX/type-traits.cpp (original)<br>
+++ cfe/trunk/test/SemaCXX/type-traits.cpp Tue Oct 24 14:31:50 2017<br>
@@ -2352,3 +2352,236 @@ void is_trivially_destructible_test() {<br>
   { int arr[F(__is_trivially_destructible(void))]; }<br>
   { int arr[F(__is_trivially_destructible(const volatile void))]; }<br>
 }<br>
+<br>
+// Instantiation of __has_unique_object_representations<br>
+template <typename T><br>
+struct has_unique_object_representations {<br>
+  static const bool value = __has_unique_object_representations(T);<br>
+};<br>
+<br>
+static_assert(!has_unique_object_representations<void>::value, "void is never unique");<br>
+static_assert(!has_unique_object_representations<const void>::value, "void is never unique");<br>
+static_assert(!has_unique_object_representations<volatile void>::value, "void is never unique");<br>
+static_assert(!has_unique_object_representations<const volatile void>::value, "void is never unique");<br>
+<br>
+static_assert(has_unique_object_representations<int>::value, "integrals are");<br>
+static_assert(has_unique_object_representations<const int>::value, "integrals are");<br>
+static_assert(has_unique_object_representations<volatile int>::value, "integrals are");<br>
+static_assert(has_unique_object_representations<const volatile int>::value, "integrals are");<br>
+<br>
+static_assert(has_unique_object_representations<void *>::value, "as are pointers");<br>
+static_assert(has_unique_object_representations<const void *>::value, "as are pointers");<br>
+static_assert(has_unique_object_representations<volatile void *>::value, "are pointers");<br>
+static_assert(has_unique_object_representations<const volatile void *>::value, "as are pointers");<br>
+<br>
+static_assert(has_unique_object_representations<int *>::value, "as are pointers");<br>
+static_assert(has_unique_object_representations<const int *>::value, "as are pointers");<br>
+static_assert(has_unique_object_representations<volatile int *>::value, "as are pointers");<br>
+static_assert(has_unique_object_representations<const volatile int *>::value, "as are pointers");<br>
+<br>
+class C {};<br>
+using FP = int (*)(int);<br>
+using PMF = int (C::*)(int);<br>
+using PMD = int C::*;<br>
+<br>
+static_assert(has_unique_object_representations<FP>::value, "even function pointers");<br>
+static_assert(has_unique_object_representations<const FP>::value, "even function pointers");<br>
+static_assert(has_unique_object_representations<volatile FP>::value, "even function pointers");<br>
+static_assert(has_unique_object_representations<const volatile FP>::value, "even function pointers");<br>
+<br>
+static_assert(has_unique_object_representations<PMF>::value, "and pointer to members");<br>
+static_assert(has_unique_object_representations<const PMF>::value, "and pointer to members");<br>
+static_assert(has_unique_object_representations<volatile PMF>::value, "and pointer to members");<br>
+static_assert(has_unique_object_representations<const volatile PMF>::value, "and pointer to members");<br>
+<br>
+static_assert(has_unique_object_representations<PMD>::value, "and pointer to members");<br>
+static_assert(has_unique_object_representations<const PMD>::value, "and pointer to members");<br>
+static_assert(has_unique_object_representations<volatile PMD>::value, "and pointer to members");<br>
+static_assert(has_unique_object_representations<const volatile PMD>::value, "and pointer to members");<br>
+<br>
+static_assert(has_unique_object_representations<bool>::value, "yes, all integral types");<br>
+static_assert(has_unique_object_representations<char>::value, "yes, all integral types");<br>
+static_assert(has_unique_object_representations<signed char>::value, "yes, all integral types");<br>
+static_assert(has_unique_object_representations<unsigned char>::value, "yes, all integral types");<br>
+static_assert(has_unique_object_representations<short>::value, "yes, all integral types");<br>
+static_assert(has_unique_object_representations<unsigned short>::value, "yes, all integral types");<br>
+static_assert(has_unique_object_representations<int>::value, "yes, all integral types");<br>
+static_assert(has_unique_object_representations<unsigned int>::value, "yes, all integral types");<br>
+static_assert(has_unique_object_representations<long>::value, "yes, all integral types");<br>
+static_assert(has_unique_object_representations<unsigned long>::value, "yes, all integral types");<br>
+static_assert(has_unique_object_representations<long long>::value, "yes, all integral types");<br>
+static_assert(has_unique_object_representations<unsigned long long>::value, "yes, all integral types");<br>
+static_assert(has_unique_object_representations<wchar_t>::value, "yes, all integral types");<br>
+static_assert(has_unique_object_representations<char16_t>::value, "yes, all integral types");<br>
+static_assert(has_unique_object_representations<char32_t>::value, "yes, all integral types");<br>
+<br>
+static_assert(!has_unique_object_representations<void>::value, "but not void!");<br>
+static_assert(!has_unique_object_representations<decltype(nullptr)>::value, "or nullptr_t");<br>
+static_assert(!has_unique_object_representations<float>::value, "definitely not Floating Point");<br>
+static_assert(!has_unique_object_representations<double>::value, "definitely not Floating Point");<br>
+static_assert(!has_unique_object_representations<long double>::value, "definitely not Floating Point");<br>
+<br>
+struct NoPadding {<br>
+  int a;<br>
+  int b;<br>
+};<br>
+<br>
+static_assert(has_unique_object_representations<NoPadding>::value, "types without padding are");<br>
+<br>
+struct InheritsFromNoPadding : NoPadding {<br>
+  int c;<br>
+  int d;<br>
+};<br>
+<br>
+static_assert(has_unique_object_representations<InheritsFromNoPadding>::value, "types without padding are");<br>
+<br>
+struct VirtuallyInheritsFromNoPadding : virtual NoPadding {<br>
+  int c;<br>
+  int d;<br>
+};<br>
+<br>
+static_assert(!has_unique_object_representations<VirtuallyInheritsFromNoPadding>::value, "No virtual inheritence");<br>
+<br>
+struct Padding {<br>
+  char a;<br>
+  int b;<br>
+};<br>
+<br>
+static_assert(!has_unique_object_representations<Padding>::value, "but not with padding");<br>
+<br>
+struct InheritsFromPadding : Padding {<br>
+  int c;<br>
+  int d;<br>
+};<br>
+<br>
+static_assert(!has_unique_object_representations<InheritsFromPadding>::value, "or its subclasses");<br>
+<br>
+struct TailPadding {<br>
+  int a;<br>
+  char b;<br>
+};<br>
+<br>
+static_assert(!has_unique_object_representations<TailPadding>::value, "even at the end");<br>
+<br>
+struct TinyStruct {<br>
+  char a;<br>
+};<br>
+<br>
+static_assert(has_unique_object_representations<TinyStruct>::value, "Should be no padding");<br>
+<br>
+struct InheritsFromTinyStruct : TinyStruct {<br>
+  int b;<br>
+};<br>
+<br>
+static_assert(!has_unique_object_representations<InheritsFromTinyStruct>::value, "Inherit causes padding");<br>
+<br>
+union NoPaddingUnion {<br>
+  int a;<br>
+  unsigned int b;<br>
+};<br>
+<br>
+static_assert(has_unique_object_representations<NoPaddingUnion>::value, "unions follow the same rules as structs");<br>
+<br>
+union PaddingUnion {<br>
+  int a;<br>
+  long long b;<br>
+};<br>
+<br>
+static_assert(!has_unique_object_representations<PaddingUnion>::value, "unions follow the same rules as structs");<br>
+<br>
+struct NotTriviallyCopyable {<br>
+  int x;<br>
+  NotTriviallyCopyable(const NotTriviallyCopyable &) {}<br>
+};<br>
+<br>
+static_assert(!has_unique_object_representations<NotTriviallyCopyable>::value, "must be trivially copyable");<br>
+<br>
+struct HasNonUniqueMember {<br>
+  float x;<br>
+};<br>
+<br>
+static_assert(!has_unique_object_representations<HasNonUniqueMember>::value, "all members must be unique");<br>
+<br>
+enum ExampleEnum { xExample,<br>
+                   yExample };<br>
+enum LLEnum : long long { xLongExample,<br>
+                          yLongExample };<br>
+<br>
+static_assert(has_unique_object_representations<ExampleEnum>::value, "Enums are integrals, so unique!");<br>
+static_assert(has_unique_object_representations<LLEnum>::value, "Enums are integrals, so unique!");<br>
+<br>
+enum class ExampleEnumClass { xExample,<br>
+                              yExample };<br>
+enum class LLEnumClass : long long { xLongExample,<br>
+                                     yLongExample };<br>
+<br>
+static_assert(has_unique_object_representations<ExampleEnumClass>::value, "Enums are integrals, so unique!");<br>
+static_assert(has_unique_object_representations<LLEnumClass>::value, "Enums are integrals, so unique!");<br>
+<br>
+// because reference types aren't object types<br>
+static_assert(!has_unique_object_representations<int &>::value, "No references!");<br>
+static_assert(!has_unique_object_representations<const int &>::value, "No references!");<br>
+static_assert(!has_unique_object_representations<volatile int &>::value, "No references!");<br>
+static_assert(!has_unique_object_representations<const volatile int &>::value, "No references!");<br>
+<br>
+static_assert(!has_unique_object_representations<Empty>::value, "No empty types!");<br>
+<br>
+class Compressed : Empty {<br>
+  int x;<br>
+};<br>
+<br>
+static_assert(has_unique_object_representations<Compressed>::value, "But inheriting from one is ok");<br>
+<br>
+class EmptyInheritor : Compressed {};<br>
+<br>
+static_assert(has_unique_object_representations<EmptyInheritor>::value, "As long as the base has items, empty is ok");<br>
+<br>
+class Dynamic {<br>
+  virtual void A();<br>
+  int i;<br>
+};<br>
+<br>
+static_assert(!has_unique_object_representations<Dynamic>::value, "Dynamic types are not valid");<br>
+<br>
+class InheritsDynamic : Dynamic {<br>
+  int j;<br>
+};<br>
+<br>
+static_assert(!has_unique_object_representations<InheritsDynamic>::value, "Dynamic types are not valid");<br>
+<br>
+static_assert(has_unique_object_representations<int[42]>::value, "Arrays are fine, as long as their value type is");<br>
+static_assert(has_unique_object_representations<int[]>::value, "Arrays are fine, as long as their value type is");<br>
+static_assert(has_unique_object_representations<int[][42]>::value, "Arrays are fine, as long as their value type is");<br>
+static_assert(!has_unique_object_representations<double[42]>::value, "So no array of doubles!");<br>
+static_assert(!has_unique_object_representations<double[]>::value, "So no array of doubles!");<br>
+static_assert(!has_unique_object_representations<double[][42]>::value, "So no array of doubles!");<br>
+<br>
+static_assert(!has_unique_object_representations<int(int)>::value, "Functions are not unique");<br>
+static_assert(!has_unique_object_representations<int(int) const>::value, "Functions are not unique");<br>
+static_assert(!has_unique_object_representations<int(int) volatile>::value, "Functions are not unique");<br>
+static_assert(!has_unique_object_representations<int(int) const volatile>::value, "Functions are not unique");<br>
+static_assert(!has_unique_object_representations<int(int) &>::value, "Functions are not unique");<br>
+static_assert(!has_unique_object_representations<int(int) const &>::value, "Functions are not unique");<br>
+static_assert(!has_unique_object_representations<int(int) volatile &>::value, "Functions are not unique");<br>
+static_assert(!has_unique_object_representations<int(int) const volatile &>::value, "Functions are not unique");<br>
+static_assert(!has_unique_object_representations<int(int) &&>::value, "Functions are not unique");<br>
+static_assert(!has_unique_object_representations<int(int) const &&>::value, "Functions are not unique");<br>
+static_assert(!has_unique_object_representations<int(int) volatile &&>::value, "Functions are not unique");<br>
+static_assert(!has_unique_object_representations<int(int) const volatile &&>::value, "Functions are not unique");<br>
+<br>
+static_assert(!has_unique_object_representations<int(int, ...)>::value, "Functions are not unique");<br>
+static_assert(!has_unique_object_representations<int(int, ...) const>::value, "Functions are not unique");<br>
+static_assert(!has_unique_object_representations<int(int, ...) volatile>::value, "Functions are not unique");<br>
+static_assert(!has_unique_object_representations<int(int, ...) const volatile>::value, "Functions are not unique");<br>
+static_assert(!has_unique_object_representations<int(int, ...) &>::value, "Functions are not unique");<br>
+static_assert(!has_unique_object_representations<int(int, ...) const &>::value, "Functions are not unique");<br>
+static_assert(!has_unique_object_representations<int(int, ...) volatile &>::value, "Functions are not unique");<br>
+static_assert(!has_unique_object_representations<int(int, ...) const volatile &>::value, "Functions are not unique");<br>
+static_assert(!has_unique_object_representations<int(int, ...) &&>::value, "Functions are not unique");<br>
+static_assert(!has_unique_object_representations<int(int, ...) const &&>::value, "Functions are not unique");<br>
+static_assert(!has_unique_object_representations<int(int, ...) volatile &&>::value, "Functions are not unique");<br>
+static_assert(!has_unique_object_representations<int(int, ...) const volatile &&>::value, "Functions are not unique");<br>
+<br>
+static auto lambda = []() {};<br>
+static_assert(!has_unique_object_representations<decltype(lambda)>::value, "Lambdas are not unique");<br>
+<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><o:p></o:p></p>
</blockquote>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</div>
</div>
</body>
</html>