summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/ComparisonCategories.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/AST/ComparisonCategories.cpp')
-rw-r--r--clang/lib/AST/ComparisonCategories.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/clang/lib/AST/ComparisonCategories.cpp b/clang/lib/AST/ComparisonCategories.cpp
index 3fb500c580e..9a07c2494ac 100644
--- a/clang/lib/AST/ComparisonCategories.cpp
+++ b/clang/lib/AST/ComparisonCategories.cpp
@@ -19,6 +19,41 @@
using namespace clang;
+Optional<ComparisonCategoryType>
+clang::getComparisonCategoryForBuiltinCmp(QualType T) {
+ using CCT = ComparisonCategoryType;
+
+ if (const ComplexType *CT = T->getAs<ComplexType>()) {
+ if (CT->getElementType()->hasFloatingRepresentation())
+ return CCT::WeakEquality;
+ // FIXME: Remove this, consistent with P1959R0.
+ return CCT::StrongEquality;
+ }
+
+ if (T->isIntegralOrEnumerationType())
+ return CCT::StrongOrdering;
+
+ if (T->hasFloatingRepresentation())
+ return CCT::PartialOrdering;
+
+ // C++2a [expr.spaceship]p7: If the composite pointer type is a function
+ // pointer type, a pointer-to-member type, or std::nullptr_t, the
+ // result is of type std::strong_equality
+ if (T->isFunctionPointerType() || T->isMemberPointerType() ||
+ T->isNullPtrType())
+ // FIXME: This case was removed by P1959R0.
+ return CCT::StrongEquality;
+
+ // C++2a [expr.spaceship]p8: If the composite pointer type is an object
+ // pointer type, p <=> q is of type std::strong_ordering.
+ // Note: this assumes neither operand is a null pointer constant.
+ if (T->isPointerType())
+ return CCT::StrongOrdering;
+
+ // TODO: Extend support for operator<=> to ObjC types.
+ return llvm::None;
+}
+
bool ComparisonCategoryInfo::ValueInfo::hasValidIntValue() const {
assert(VD && "must have var decl");
if (!VD->checkInitIsICE())
OpenPOWER on IntegriCloud