PODness and Type Traits

Make C++ classes track the POD property (C++ [class]p4)
Track the existence of a copy assignment operator.
Implicitly declare the copy assignment operator if none is provided.
Implement most of the parsing job for the G++ type traits extension.
Fully implement the low-hanging fruit of the type traits:
__is_pod: Whether a type is a POD.
__is_class: Whether a type is a (non-union) class.
__is_union: Whether a type is a union.
__is_enum: Whether a type is an enum.
__is_polymorphic: Whether a type is polymorphic (C++ [class.virtual]p1).



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61746 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp
index c70ad4a..1d42b64 100644
--- a/lib/AST/Type.cpp
+++ b/lib/AST/Type.cpp
@@ -670,6 +670,42 @@
   }
 }
 
+/// isPODType - Return true if this is a plain-old-data type (C++ 3.9p10)
+bool Type::isPODType() const {
+  // The compiler shouldn't query this for incomplete types, but the user might.
+  // We return false for that case.
+  if (isIncompleteType())
+    return false;
+
+  switch (CanonicalType->getTypeClass()) {
+    // Everything not explicitly mentioned is not POD.
+  default: return false;
+  case ASQual:
+    return cast<ASQualType>(CanonicalType)->getBaseType()->isPODType();
+  case VariableArray:
+  case ConstantArray:
+    // IncompleteArray is caught by isIncompleteType() above.
+    return cast<ArrayType>(CanonicalType)->getElementType()->isPODType();
+
+  case Builtin:
+  case Complex:
+  case Pointer:
+  case Vector:
+  case ExtVector:
+    // FIXME: pointer-to-member
+    return true;
+
+  case Tagged:
+    if (isEnumeralType())
+      return true;
+    if (CXXRecordDecl *RDecl = dyn_cast<CXXRecordDecl>(
+          cast<TagType>(CanonicalType)->getDecl()))
+      return RDecl->isPOD();
+    // C struct/union is POD.
+    return true;
+  }
+}
+
 bool Type::isPromotableIntegerType() const {
   if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
     return ASQT->getBaseType()->isPromotableIntegerType();