[cfe-commits] r63395 - in /cfe/trunk: include/clang/AST/Type.h lib/AST/Type.cpp lib/Analysis/GRExprEngine.cpp lib/Sema/SemaDecl.cpp lib/Sema/SemaInit.cpp

Douglas Gregor dgregor at apple.com
Fri Jan 30 09:31:03 PST 2009


Author: dgregor
Date: Fri Jan 30 11:31:00 2009
New Revision: 63395

URL: http://llvm.org/viewvc/llvm-project?rev=63395&view=rev
Log:
Switch Type::isAggregateType to use the C++ definition of "aggregate
type" rather than the C definition. We do this because both C99 and
Clang always use "aggregate type" as "aggregate or union type", and
the C++ definition includes union types.


Modified:
    cfe/trunk/include/clang/AST/Type.h
    cfe/trunk/lib/AST/Type.cpp
    cfe/trunk/lib/Analysis/GRExprEngine.cpp
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/lib/Sema/SemaInit.cpp

Modified: cfe/trunk/include/clang/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=63395&r1=63394&r2=63395&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Fri Jan 30 11:31:00 2009
@@ -328,7 +328,7 @@
   bool isVoidType() const;         // C99 6.2.5p19
   bool isDerivedType() const;      // C99 6.2.5p20
   bool isScalarType() const;       // C99 6.2.5p21 (arithmetic + pointers)
-  bool isAggregateType() const;    // C99 6.2.5p21 (arrays, structures)
+  bool isAggregateType() const;
   
   // Type Predicates: Check to see if this type is structurally the specified
   // type, ignoring typedefs and qualifiers.

Modified: cfe/trunk/lib/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=63395&r1=63394&r2=63395&view=diff

==============================================================================
--- cfe/trunk/lib/AST/Type.cpp (original)
+++ cfe/trunk/lib/AST/Type.cpp Fri Jan 30 11:31:00 2009
@@ -661,12 +661,20 @@
          isa<ObjCQualifiedIdType>(CanonicalType);
 }
 
+/// \brief Determines whether the type is a C++ aggregate type or C
+/// aggregate or union type.
+///
+/// An aggregate type is an array or a class type (struct, union, or
+/// class) that has no user-declared constructors, no private or
+/// protected non-static data members, no base classes, and no virtual
+/// functions (C++ [dcl.init.aggr]p1). The notion of an aggregate type
+/// subsumes the notion of C aggregates (C99 6.2.5p21) because it also
+/// includes union types.
 bool Type::isAggregateType() const {
-  if (const TagType *TT = dyn_cast<TagType>(CanonicalType)) {
-    if (TT->getDecl()->isStruct())
-      return true;
-    return false;
-  }
+  if (const CXXRecordType *CXXClassType = dyn_cast<CXXRecordType>(CanonicalType))
+    return CXXClassType->getDecl()->isAggregate();
+  if (isa<RecordType>(CanonicalType))
+    return true;
   if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
     return ASQT->getBaseType()->isAggregateType();
   return isa<ArrayType>(CanonicalType);

Modified: cfe/trunk/lib/Analysis/GRExprEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/GRExprEngine.cpp?rev=63395&r1=63394&r2=63395&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/GRExprEngine.cpp (original)
+++ cfe/trunk/lib/Analysis/GRExprEngine.cpp Fri Jan 30 11:31:00 2009
@@ -493,8 +493,7 @@
       // can be used in a lvalue context.  We need to enhance our support
       // of such temporaries in both the environment and the store, so right
       // now we just do a regular visit.
-      assert ((Ex->getType()->isAggregateType() || 
-              Ex->getType()->isUnionType()) &&
+      assert ((Ex->getType()->isAggregateType()) &&
               "Other kinds of expressions with non-aggregate/union types do"
               " not have lvalues.");
       

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=63395&r1=63394&r2=63395&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Jan 30 11:31:00 2009
@@ -1083,6 +1083,7 @@
     // we have an initializer list and a destination type that is not
     // an aggregate.
     // FIXME: In C++0x, this is yet another form of initialization.
+    // FIXME: Move this checking into CheckInitList!
     if (const RecordType *ClassRec = DeclType->getAsRecordType()) {
       const CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>(ClassRec->getDecl());
       if (!ClassDecl->isAggregate())

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=63395&r1=63394&r2=63395&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Fri Jan 30 11:31:00 2009
@@ -287,8 +287,8 @@
     CheckScalarType(IList, DeclType, Index, StructuredList, StructuredIndex);
   } else if (DeclType->isVectorType()) {
     CheckVectorType(IList, DeclType, Index, StructuredList, StructuredIndex);
-  } else if (DeclType->isAggregateType() || DeclType->isUnionType()) {
-    if (DeclType->isStructureType() || DeclType->isUnionType()) {
+  } else if (DeclType->isAggregateType()) {
+    if (DeclType->isRecordType()) {
       RecordDecl *RD = DeclType->getAsRecordType()->getDecl();
       CheckStructUnionTypes(IList, DeclType, RD->field_begin(), 
                             SubobjectIsDesignatorContext, Index,





More information about the cfe-commits mailing list