[cfe-commits] [Patch] Implement compiler intrinsics for MSVC 2012 type_traits

Richard Smith richard at metafoo.co.uk
Fri Jan 18 18:12:04 PST 2013


On Thu, Jan 17, 2013 at 9:51 PM, Ryan Molden <ryanmolden at gmail.com> wrote:
> On Thu, Jan 10, 2013 at 9:40 PM, Ryan Molden <ryanmolden at gmail.com> wrote:
>>>
>>>
>>> Please rebase the patch against the latest trunk -- in order to
>>> approximately match GCC, we now return false from the __has_trivial_*
>>> and __has_nothrow_* builtins if the class has both a trivial such
>>> special member and a nontrivial one.
>>>
>>> Ultimately, I wonder if we should just ignore GCC's specification for
>>> how these builtins should work, and instead implement the semantics of
>>> the corresponding C++11 type traits here. It's actually not possible
>>> to implement the traits correctly from the defined semantics of the
>>> traits which libstdc++ and MSVC's STL use.
>>
>>
>> Attached is a patch against trunk, I believe I picked up / merged your
>> recent changes properly, let me know if I mucked it up or misunderstood you
>> (I just merged your changes I didn't augment the code I had in there from
>> before your changes).
>> I am all for matching the standard regardless of what GCC/MSVC decide(d)
>> to do here, I assume if they are non-standard at the moment they will soon
>> get in line.
>>
>> Earlier (last week?) I sent a mail about seeing some build issues with
>> macho_dump.I don't believe they are caused by my changes, clang still builds
>> and the tests still pass, but it is unclear what the failures mean or how to
>> investigate them, which is why I hadn't yet sent the patch.
>>
>> Ryan
>
>
> Anything else I need to do here? I haven't seen a check-in mail, then again
> there have been hundreds of mails so perhaps I missed it, or there is some
> formal process to go through to request submission?

Sorry for the delay! Just a handful of things:

HasNoThrowOperator should check RD->*HasTrivial() &&
!RD->*HasNonTrivial() to match the other predicates.

+  case UTT_HasTrivialMoveConstructor:
+    //  This trait is implemented by MSVC 2012 and needed to parse the
+    //  standard library headers. Specifically this is used as the logic
+    //  behind std::has_trivial_move_constructor (20.9.4.3).
+    if (T.isPODType(Self.Context))
+      return true;
+    if (const RecordType *RT = C.getBaseElementType(T)->getAs<RecordType>())
+      return cast<CXXRecordDecl>(RT->getDecl())->hasTrivialMoveConstructor();

Again, to match the other predicates, this should be
hasTrivialMoveConstructor() && !hasNonTrivialMoveConstructor().

+  case UTT_HasTrivialMoveAssign:
+    //  This trait is implemented by MSVC 2012 and needed to parse the
+    //  standard library headers. Specifically it is used as the logic
+    //  behind std::is_trivially_move_assignable (20.9.4.3)
+    if (T.isPODType(Self.Context))
+      return true;
+    if (const RecordType *RT = C.getBaseElementType(T)->getAs<RecordType>())
+      return cast<CXXRecordDecl>(RT->getDecl())->hasTrivialMoveAssignment();

Likewise.

@@ -3147,35 +3203,25 @@
     if (CXXRecordDecl *RD = T->getAsCXXRecordDecl()) {
       if (RD->hasTrivialCopyAssignment() && !RD->hasNonTrivialCopyAssignment())
         return true;
+    }

No braces here. Though, in fact, this check is covered by the next
call, so just delete it.

+    if(const RecordType *RT = T->getAs<RecordType>())
+      return HasNoThrowOperator(RT, OO_Equal, Self, KeyLoc, C,
+                                &CXXRecordDecl::hasTrivialCopyAssignment,
+                                &CXXMethodDecl::isCopyAssignmentOperator);

Missing space after 'if'.



More information about the cfe-commits mailing list