<div dir="auto">Incremental progress is fine :)</div><div class="gmail_extra"><br><div class="gmail_quote">On 26 Oct 2017 09:53, "Keane, Erich via cfe-commits" <<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">





<div lang="EN-US" link="blue" vlink="purple">
<div class="m_3205005665839481213WordSection1">
<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?<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></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:<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>]
<br>
<b>Sent:</b> Thursday, October 26, 2017 9:50 AM<div class="quoted-text"><br>
<b>To:</b> Keane, Erich <<a href="mailto:erich.keane@intel.com" target="_blank">erich.keane@intel.com</a>><br>
<b>Cc:</b> cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>><br>
<b>Subject:</b> Re: r316518 - mplement __has_unique_object_<wbr>representations<u></u><u></u></div></span></p>
<p class="MsoNormal"><u></u> <u></u></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" target="_blank">cfe-commits@lists.llvm.org</a>> wrote:<u></u><u></u></p><div class="elided-text">
<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-<wbr>project?rev=316518&view=rev</a><br>
Log:<br>
mplement __has_unique_object_<wbr>representations<br>
<br>
A helper builtin to facilitate implementing the<br>
std::has_unique_object_<wbr>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_<wbr>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/<wbr>D39064</a><br>
<br>
Modified:<br>
    cfe/trunk/include/clang/AST/<wbr>Type.h<br>
    cfe/trunk/include/clang/Basic/<wbr>TokenKinds.def<br>
    cfe/trunk/include/clang/Basic/<wbr>TypeTraits.h<br>
    cfe/trunk/lib/AST/Type.cpp<br>
    cfe/trunk/lib/Parse/ParseExpr.<wbr>cpp<br>
    cfe/trunk/lib/Sema/<wbr>SemaExprCXX.cpp<br>
    cfe/trunk/test/SemaCXX/type-<wbr>traits.cpp<br>
<br>
Modified: cfe/trunk/include/clang/AST/<wbr>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-<wbr>project/cfe/trunk/include/<wbr>clang/AST/Type.h?rev=316518&<wbr>r1=316517&r2=316518&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/include/clang/AST/<wbr>Type.h (original)<br>
+++ cfe/trunk/include/clang/AST/<wbr>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<wbr>(const ASTContext &Context) const;<u></u><u></u></p>
</blockquote>
</div></div>
</div>
</div><div class="elided-text">
<div>
<p class="MsoNormal"><u></u> <u></u></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.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></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 unionHasUniqueObjectRepresenta<wbr>tions(const ASTContext& Context) const;<br>
+  bool structHasUniqueObjectRepresent<wbr>ations(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/<wbr>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-<wbr>project/cfe/trunk/include/<wbr>clang/Basic/TokenKinds.def?<wbr>rev=316518&r1=316517&r2=<wbr>316518&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/include/clang/Basic/<wbr>TokenKinds.def (original)<br>
+++ cfe/trunk/include/clang/Basic/<wbr>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_<wbr>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_<wbr>object_representations,<br>
+             <wbr>HasUniqueObjectRepresentations<wbr>, KEYCXX)<br>
<br>
 // Clang-only C++ Type Traits<br>
 TYPE_TRAIT_N(__is_trivially_<wbr>constructible, IsTriviallyConstructible, KEYCXX)<br>
<br>
Modified: cfe/trunk/include/clang/Basic/<wbr>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-<wbr>project/cfe/trunk/include/<wbr>clang/Basic/TypeTraits.h?rev=<wbr>316518&r1=316517&r2=316518&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/include/clang/Basic/<wbr>TypeTraits.h (original)<br>
+++ cfe/trunk/include/clang/Basic/<wbr>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_<wbr>HasUniqueObjectRepresentations<wbr>,<br>
+    UTT_Last = UTT_<wbr>HasUniqueObjectRepresentations<wbr>,<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-<wbr>project/cfe/trunk/lib/AST/<wbr>Type.cpp?rev=316518&r1=316517&<wbr>r2=316518&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<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::<wbr>isTriviallyCopyableType(c<br>
   return false;<br>
 }<br>
<br>
+bool QualType::<wbr>unionHasUniqueObjectRepresenta<wbr>tions(<br>
+    const ASTContext &Context) const {<br>
+  assert((*this)->isUnionType() && "must be union type");<br>
+  CharUnits UnionSize = Context.getTypeSizeInChars(*<wbr>this);<br>
+  const RecordDecl *Union = getTypePtr()->getAs<<wbr>RecordType>()->getDecl();<br>
+<br>
+  for (const auto *Field : Union->fields()) {<br>
+    if (!Field->getType().<wbr>hasUniqueObjectRepresentations<wbr>(Context))<br>
+      return false;<br>
+    CharUnits FieldSize = Context.getTypeSizeInChars(<wbr>Field->getType());<br>
+    if (FieldSize != UnionSize)<br>
+      return false;<br>
+  }<br>
+  return true;<br>
+}<br>
+<br>
+bool isStructEmpty(QualType Ty) {<br>
+  assert(Ty.getTypePtr()-><wbr>isStructureOrClassType() &&<br>
+         "Must be struct or class");<br>
+  const RecordDecl *RD = Ty.getTypePtr()->getAs<<wbr>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::<wbr>structHasUniqueObjectRepresent<wbr>ations(<br>
+    const ASTContext &Context) const {<br>
+  assert((*this)-><wbr>isStructureOrClassType() && "Must be struct or class");<br>
+  const RecordDecl *RD = getTypePtr()->getAs<<wbr>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;<u></u><u></u></p>
</blockquote>
</div>
</div>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></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?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></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.<u></u><u></u></p>
</blockquote>
</div>
</div>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></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.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></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.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></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()<wbr>)) {<br>
+        if (!Base.getType().<wbr>structHasUniqueObjectRepresent<wbr>ations(Context))<br>
+          return false;<br>
+        BaseSize += Context.getTypeSizeInChars(<wbr>Base.getType());<br>
+      }<br>
+    }<br>
+  }<br>
+<br>
+  CharUnits StructSize = Context.getTypeSizeInChars(*<wbr>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>
+  ;<u></u><u></u></p>
</blockquote>
</div>
</div>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Stray semicolon?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></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(<wbr>Context.getFieldOffset(*RD-><wbr>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().<wbr>hasUniqueObjectRepresentations<wbr>(Context))<br>
+      return false;<br>
+    CharUnits FieldSize = Context.getTypeSizeInChars(<wbr>Field->getType());<br>
+    CharUnits FieldOffset =<br>
+        Context.toCharUnitsFromBits(<wbr>Context.getFieldOffset(Field))<wbr>;<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::<wbr>hasUniqueObjectRepresentations<wbr>(const ASTContext &Context) const {<br>
+  // C++17 [meta.unary.prop]:<br>
+  //   The predicate condition for a template specialization<br>
+  //   has_unique_object_<wbr>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(*<wbr>this).<wbr>hasUniqueObjectRepresentations<wbr>(<br>
+        Context);<u></u><u></u></p>
</blockquote>
</div>
</div>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></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.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></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(<wbr>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)-><wbr>isIntegralOrEnumerationType())<br>
+    return true;<br>
+<br>
+  // All pointers are unique, since they're just integrals.<u></u><u></u></p>
</blockquote>
</div>
</div>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></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.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></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()<wbr>)<br>
+    return true;<br>
+<br>
+  if ((*this)->isRecordType()) {<br>
+    const RecordDecl *Record = getTypePtr()->getAs<<wbr>RecordType>()->getDecl();<br>
+<br>
+    // Lambda types are not unique, so exclude them immediately.<u></u><u></u></p>
</blockquote>
</div>
</div>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Why?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></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 unionHasUniqueObjectRepresenta<wbr>tions(Context);<br>
+    return structHasUniqueObjectRepresent<wbr>ations(Context);<u></u><u></u></p>
</blockquote>
</div>
</div>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></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.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></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::<wbr>isNonWeakInMRRWithObjCWeak(<wbr>const ASTContext &Context) const {<br>
   return !Context.getLangOpts().<wbr>ObjCAutoRefCount &&<br>
          Context.getLangOpts().ObjCWeak &&<br>
<br>
Modified: cfe/trunk/lib/Parse/ParseExpr.<wbr>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-<wbr>project/cfe/trunk/lib/Parse/<wbr>ParseExpr.cpp?rev=316518&r1=<wbr>316517&r2=316518&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/Parse/ParseExpr.<wbr>cpp (original)<br>
+++ cfe/trunk/lib/Parse/ParseExpr.<wbr>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_<wbr>representations'<br>
 ///<br>
 /// [Clang] unary-type-trait:<br>
 ///                   '__is_aggregate'<br>
<br>
Modified: cfe/trunk/lib/Sema/<wbr>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-<wbr>project/cfe/trunk/lib/Sema/<wbr>SemaExprCXX.cpp?rev=316518&r1=<wbr>316517&r2=316518&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/lib/Sema/<wbr>SemaExprCXX.cpp (original)<br>
+++ cfe/trunk/lib/Sema/<wbr>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_<wbr>HasUniqueObjectRepresentations<wbr>:<br>
     if (ArgTy->isIncompleteArrayType(<wbr>) || 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_<wbr>HasUniqueObjectRepresentations<wbr>:<br>
+    return T.<wbr>hasUniqueObjectRepresentations<wbr>(C);<br>
   }<br>
 }<br>
<br>
<br>
Modified: cfe/trunk/test/SemaCXX/type-<wbr>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-<wbr>project/cfe/trunk/test/<wbr>SemaCXX/type-traits.cpp?rev=<wbr>316518&r1=316517&r2=316518&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- cfe/trunk/test/SemaCXX/type-<wbr>traits.cpp (original)<br>
+++ cfe/trunk/test/SemaCXX/type-<wbr>traits.cpp Tue Oct 24 14:31:50 2017<br>
@@ -2352,3 +2352,236 @@ void is_trivially_destructible_<wbr>test() {<br>
   { int arr[F(__is_trivially_<wbr>destructible(void))]; }<br>
   { int arr[F(__is_trivially_<wbr>destructible(const volatile void))]; }<br>
 }<br>
+<br>
+// Instantiation of __has_unique_object_<wbr>representations<br>
+template <typename T><br>
+struct has_unique_object_<wbr>representations {<br>
+  static const bool value = __has_unique_object_<wbr>representations(T);<br>
+};<br>
+<br>
+static_assert(!has_unique_<wbr>object_representations<void>::<wbr>value, "void is never unique");<br>
+static_assert(!has_unique_<wbr>object_representations<const void>::value, "void is never unique");<br>
+static_assert(!has_unique_<wbr>object_representations<<wbr>volatile void>::value, "void is never unique");<br>
+static_assert(!has_unique_<wbr>object_representations<const volatile void>::value, "void is never unique");<br>
+<br>
+static_assert(has_unique_<wbr>object_representations<int>::<wbr>value, "integrals are");<br>
+static_assert(has_unique_<wbr>object_representations<const int>::value, "integrals are");<br>
+static_assert(has_unique_<wbr>object_representations<<wbr>volatile int>::value, "integrals are");<br>
+static_assert(has_unique_<wbr>object_representations<const volatile int>::value, "integrals are");<br>
+<br>
+static_assert(has_unique_<wbr>object_representations<void *>::value, "as are pointers");<br>
+static_assert(has_unique_<wbr>object_representations<const void *>::value, "as are pointers");<br>
+static_assert(has_unique_<wbr>object_representations<<wbr>volatile void *>::value, "are pointers");<br>
+static_assert(has_unique_<wbr>object_representations<const volatile void *>::value, "as are pointers");<br>
+<br>
+static_assert(has_unique_<wbr>object_representations<int *>::value, "as are pointers");<br>
+static_assert(has_unique_<wbr>object_representations<const int *>::value, "as are pointers");<br>
+static_assert(has_unique_<wbr>object_representations<<wbr>volatile int *>::value, "as are pointers");<br>
+static_assert(has_unique_<wbr>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_<wbr>object_representations<FP>::<wbr>value, "even function pointers");<br>
+static_assert(has_unique_<wbr>object_representations<const FP>::value, "even function pointers");<br>
+static_assert(has_unique_<wbr>object_representations<<wbr>volatile FP>::value, "even function pointers");<br>
+static_assert(has_unique_<wbr>object_representations<const volatile FP>::value, "even function pointers");<br>
+<br>
+static_assert(has_unique_<wbr>object_representations<PMF>::<wbr>value, "and pointer to members");<br>
+static_assert(has_unique_<wbr>object_representations<const PMF>::value, "and pointer to members");<br>
+static_assert(has_unique_<wbr>object_representations<<wbr>volatile PMF>::value, "and pointer to members");<br>
+static_assert(has_unique_<wbr>object_representations<const volatile PMF>::value, "and pointer to members");<br>
+<br>
+static_assert(has_unique_<wbr>object_representations<PMD>::<wbr>value, "and pointer to members");<br>
+static_assert(has_unique_<wbr>object_representations<const PMD>::value, "and pointer to members");<br>
+static_assert(has_unique_<wbr>object_representations<<wbr>volatile PMD>::value, "and pointer to members");<br>
+static_assert(has_unique_<wbr>object_representations<const volatile PMD>::value, "and pointer to members");<br>
+<br>
+static_assert(has_unique_<wbr>object_representations<bool>::<wbr>value, "yes, all integral types");<br>
+static_assert(has_unique_<wbr>object_representations<char>::<wbr>value, "yes, all integral types");<br>
+static_assert(has_unique_<wbr>object_representations<signed char>::value, "yes, all integral types");<br>
+static_assert(has_unique_<wbr>object_representations<<wbr>unsigned char>::value, "yes, all integral types");<br>
+static_assert(has_unique_<wbr>object_representations<short>:<wbr>:value, "yes, all integral types");<br>
+static_assert(has_unique_<wbr>object_representations<<wbr>unsigned short>::value, "yes, all integral types");<br>
+static_assert(has_unique_<wbr>object_representations<int>::<wbr>value, "yes, all integral types");<br>
+static_assert(has_unique_<wbr>object_representations<<wbr>unsigned int>::value, "yes, all integral types");<br>
+static_assert(has_unique_<wbr>object_representations<long>::<wbr>value, "yes, all integral types");<br>
+static_assert(has_unique_<wbr>object_representations<<wbr>unsigned long>::value, "yes, all integral types");<br>
+static_assert(has_unique_<wbr>object_representations<long long>::value, "yes, all integral types");<br>
+static_assert(has_unique_<wbr>object_representations<<wbr>unsigned long long>::value, "yes, all integral types");<br>
+static_assert(has_unique_<wbr>object_representations<wchar_<wbr>t>::value, "yes, all integral types");<br>
+static_assert(has_unique_<wbr>object_representations<char16_<wbr>t>::value, "yes, all integral types");<br>
+static_assert(has_unique_<wbr>object_representations<char32_<wbr>t>::value, "yes, all integral types");<br>
+<br>
+static_assert(!has_unique_<wbr>object_representations<void>::<wbr>value, "but not void!");<br>
+static_assert(!has_unique_<wbr>object_representations<<wbr>decltype(nullptr)>::value, "or nullptr_t");<br>
+static_assert(!has_unique_<wbr>object_representations<float>:<wbr>:value, "definitely not Floating Point");<br>
+static_assert(!has_unique_<wbr>object_representations<double><wbr>::value, "definitely not Floating Point");<br>
+static_assert(!has_unique_<wbr>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_<wbr>object_representations<<wbr>NoPadding>::value, "types without padding are");<br>
+<br>
+struct InheritsFromNoPadding : NoPadding {<br>
+  int c;<br>
+  int d;<br>
+};<br>
+<br>
+static_assert(has_unique_<wbr>object_representations<<wbr>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_<wbr>object_representations<<wbr>VirtuallyInheritsFromNoPadding<wbr>>::value, "No virtual inheritence");<br>
+<br>
+struct Padding {<br>
+  char a;<br>
+  int b;<br>
+};<br>
+<br>
+static_assert(!has_unique_<wbr>object_representations<<wbr>Padding>::value, "but not with padding");<br>
+<br>
+struct InheritsFromPadding : Padding {<br>
+  int c;<br>
+  int d;<br>
+};<br>
+<br>
+static_assert(!has_unique_<wbr>object_representations<<wbr>InheritsFromPadding>::value, "or its subclasses");<br>
+<br>
+struct TailPadding {<br>
+  int a;<br>
+  char b;<br>
+};<br>
+<br>
+static_assert(!has_unique_<wbr>object_representations<<wbr>TailPadding>::value, "even at the end");<br>
+<br>
+struct TinyStruct {<br>
+  char a;<br>
+};<br>
+<br>
+static_assert(has_unique_<wbr>object_representations<<wbr>TinyStruct>::value, "Should be no padding");<br>
+<br>
+struct InheritsFromTinyStruct : TinyStruct {<br>
+  int b;<br>
+};<br>
+<br>
+static_assert(!has_unique_<wbr>object_representations<<wbr>InheritsFromTinyStruct>::<wbr>value, "Inherit causes padding");<br>
+<br>
+union NoPaddingUnion {<br>
+  int a;<br>
+  unsigned int b;<br>
+};<br>
+<br>
+static_assert(has_unique_<wbr>object_representations<<wbr>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_<wbr>object_representations<<wbr>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_<wbr>object_representations<<wbr>NotTriviallyCopyable>::value, "must be trivially copyable");<br>
+<br>
+struct HasNonUniqueMember {<br>
+  float x;<br>
+};<br>
+<br>
+static_assert(!has_unique_<wbr>object_representations<<wbr>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_<wbr>object_representations<<wbr>ExampleEnum>::value, "Enums are integrals, so unique!");<br>
+static_assert(has_unique_<wbr>object_representations<LLEnum><wbr>::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_<wbr>object_representations<<wbr>ExampleEnumClass>::value, "Enums are integrals, so unique!");<br>
+static_assert(has_unique_<wbr>object_representations<<wbr>LLEnumClass>::value, "Enums are integrals, so unique!");<br>
+<br>
+// because reference types aren't object types<br>
+static_assert(!has_unique_<wbr>object_representations<int &>::value, "No references!");<br>
+static_assert(!has_unique_<wbr>object_representations<const int &>::value, "No references!");<br>
+static_assert(!has_unique_<wbr>object_representations<<wbr>volatile int &>::value, "No references!");<br>
+static_assert(!has_unique_<wbr>object_representations<const volatile int &>::value, "No references!");<br>
+<br>
+static_assert(!has_unique_<wbr>object_representations<Empty>:<wbr>:value, "No empty types!");<br>
+<br>
+class Compressed : Empty {<br>
+  int x;<br>
+};<br>
+<br>
+static_assert(has_unique_<wbr>object_representations<<wbr>Compressed>::value, "But inheriting from one is ok");<br>
+<br>
+class EmptyInheritor : Compressed {};<br>
+<br>
+static_assert(has_unique_<wbr>object_representations<<wbr>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_<wbr>object_representations<<wbr>Dynamic>::value, "Dynamic types are not valid");<br>
+<br>
+class InheritsDynamic : Dynamic {<br>
+  int j;<br>
+};<br>
+<br>
+static_assert(!has_unique_<wbr>object_representations<<wbr>InheritsDynamic>::value, "Dynamic types are not valid");<br>
+<br>
+static_assert(has_unique_<wbr>object_representations<int[42]<wbr>>::value, "Arrays are fine, as long as their value type is");<br>
+static_assert(has_unique_<wbr>object_representations<int[]>:<wbr>:value, "Arrays are fine, as long as their value type is");<br>
+static_assert(has_unique_<wbr>object_representations<int[][<wbr>42]>::value, "Arrays are fine, as long as their value type is");<br>
+static_assert(!has_unique_<wbr>object_representations<double[<wbr>42]>::value, "So no array of doubles!");<br>
+static_assert(!has_unique_<wbr>object_representations<double[<wbr>]>::value, "So no array of doubles!");<br>
+static_assert(!has_unique_<wbr>object_representations<double[<wbr>][42]>::value, "So no array of doubles!");<br>
+<br>
+static_assert(!has_unique_<wbr>object_representations<int(<wbr>int)>::value, "Functions are not unique");<br>
+static_assert(!has_unique_<wbr>object_representations<int(<wbr>int) const>::value, "Functions are not unique");<br>
+static_assert(!has_unique_<wbr>object_representations<int(<wbr>int) volatile>::value, "Functions are not unique");<br>
+static_assert(!has_unique_<wbr>object_representations<int(<wbr>int) const volatile>::value, "Functions are not unique");<br>
+static_assert(!has_unique_<wbr>object_representations<int(<wbr>int) &>::value, "Functions are not unique");<br>
+static_assert(!has_unique_<wbr>object_representations<int(<wbr>int) const &>::value, "Functions are not unique");<br>
+static_assert(!has_unique_<wbr>object_representations<int(<wbr>int) volatile &>::value, "Functions are not unique");<br>
+static_assert(!has_unique_<wbr>object_representations<int(<wbr>int) const volatile &>::value, "Functions are not unique");<br>
+static_assert(!has_unique_<wbr>object_representations<int(<wbr>int) &&>::value, "Functions are not unique");<br>
+static_assert(!has_unique_<wbr>object_representations<int(<wbr>int) const &&>::value, "Functions are not unique");<br>
+static_assert(!has_unique_<wbr>object_representations<int(<wbr>int) volatile &&>::value, "Functions are not unique");<br>
+static_assert(!has_unique_<wbr>object_representations<int(<wbr>int) const volatile &&>::value, "Functions are not unique");<br>
+<br>
+static_assert(!has_unique_<wbr>object_representations<int(<wbr>int, ...)>::value, "Functions are not unique");<br>
+static_assert(!has_unique_<wbr>object_representations<int(<wbr>int, ...) const>::value, "Functions are not unique");<br>
+static_assert(!has_unique_<wbr>object_representations<int(<wbr>int, ...) volatile>::value, "Functions are not unique");<br>
+static_assert(!has_unique_<wbr>object_representations<int(<wbr>int, ...) const volatile>::value, "Functions are not unique");<br>
+static_assert(!has_unique_<wbr>object_representations<int(<wbr>int, ...) &>::value, "Functions are not unique");<br>
+static_assert(!has_unique_<wbr>object_representations<int(<wbr>int, ...) const &>::value, "Functions are not unique");<br>
+static_assert(!has_unique_<wbr>object_representations<int(<wbr>int, ...) volatile &>::value, "Functions are not unique");<br>
+static_assert(!has_unique_<wbr>object_representations<int(<wbr>int, ...) const volatile &>::value, "Functions are not unique");<br>
+static_assert(!has_unique_<wbr>object_representations<int(<wbr>int, ...) &&>::value, "Functions are not unique");<br>
+static_assert(!has_unique_<wbr>object_representations<int(<wbr>int, ...) const &&>::value, "Functions are not unique");<br>
+static_assert(!has_unique_<wbr>object_representations<int(<wbr>int, ...) volatile &&>::value, "Functions are not unique");<br>
+static_assert(!has_unique_<wbr>object_representations<int(<wbr>int, ...) const volatile &&>::value, "Functions are not unique");<br>
+<br>
+static auto lambda = []() {};<br>
+static_assert(!has_unique_<wbr>object_representations<<wbr>decltype(lambda)>::value, "Lambdas are not unique");<br>
+<br>
<br>
<br>
______________________________<wbr>_________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">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/<wbr>mailman/listinfo/cfe-commits</a><u></u><u></u></p>
</blockquote>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
</div></div>
</div>
</div>

<br>______________________________<wbr>_________________<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" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-commits</a><br>
<br></blockquote></div><br></div>