r196646 - Type traits: No need for switch to handle __builtin_types_compatible_p

Alp Toker alp at nuanti.com
Fri Dec 6 23:20:22 PST 2013


Author: alp
Date: Sat Dec  7 01:20:22 2013
New Revision: 196646

URL: http://llvm.org/viewvc/llvm-project?rev=196646&view=rev
Log:
Type traits: No need for switch to handle __builtin_types_compatible_p

__builtin_types_compatible_p() isn't a C++ type trait at all, rather a GNU C
special-case, so it's fine to use BoolTy the default return type for binary
type traits.

This brings BTT in line with other arities that already default to BoolTy.

Cleanup only, no change in behaviour.

Modified:
    cfe/trunk/lib/Sema/SemaExprCXX.cpp

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=196646&r1=196645&r2=196646&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Sat Dec  7 01:20:22 2013
@@ -3938,16 +3938,10 @@ ExprResult Sema::BuildBinaryTypeTrait(Bi
   if (!LhsT->isDependentType() && !RhsT->isDependentType())
     Value = EvaluateBinaryTypeTrait(*this, BTT, LhsT, RhsT, KWLoc);
 
-  // Select trait result type.
-  QualType ResultType;
-  switch (BTT) {
-  case BTT_IsBaseOf:       ResultType = Context.BoolTy; break;
-  case BTT_IsConvertible:  ResultType = Context.BoolTy; break;
-  case BTT_IsSame:         ResultType = Context.BoolTy; break;
-  case BTT_TypeCompatible: ResultType = Context.IntTy; break;
-  case BTT_IsConvertibleTo: ResultType = Context.BoolTy; break;
-  case BTT_IsTriviallyAssignable: ResultType = Context.BoolTy;
-  }
+  QualType ResultType = Context.BoolTy;
+  // __builtin_types_compatible_p is a GNU C extension, not a C++ type trait.
+  if (BTT == BTT_TypeCompatible)
+    ResultType = Context.IntTy;
 
   return Owned(new (Context) BinaryTypeTraitExpr(KWLoc, BTT, LhsTSInfo,
                                                  RhsTSInfo, Value, RParen,





More information about the cfe-commits mailing list