[cfe-commits] r86129 - in /cfe/trunk: lib/Sema/Sema.h lib/Sema/SemaCXXCast.cpp lib/Sema/SemaDeclCXX.cpp lib/Sema/SemaOverload.cpp test/SemaTemplate/instantiate-complete.cpp utils/C++Tests/LLVM-Syntax/lit.local.cfg

Douglas Gregor dgregor at apple.com
Thu Nov 5 05:06:38 PST 2009


Author: dgregor
Date: Thu Nov  5 07:06:35 2009
New Revision: 86129

URL: http://llvm.org/viewvc/llvm-project?rev=86129&view=rev
Log:
Fixed two places where we needed to force completion of a type
(without complaining if it fails) to get proper semantics: reference
binding with a derived-to-base conversion and the enumeration of
constructors for user-defined conversions. There are probably more
cases to fix, but my prior attempt at statically ensuring that
complete-type checking always happens failed. Perhaps I'll try again.

With this change, Clang can parse include/llvm/*.h!


Modified:
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaCXXCast.cpp
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp
    cfe/trunk/lib/Sema/SemaOverload.cpp
    cfe/trunk/test/SemaTemplate/instantiate-complete.cpp
    cfe/trunk/utils/C++Tests/LLVM-Syntax/lit.local.cfg

Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=86129&r1=86128&r2=86129&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Thu Nov  5 07:06:35 2009
@@ -3651,7 +3651,8 @@
     Ref_Compatible
   };
 
-  ReferenceCompareResult CompareReferenceRelationship(QualType T1, QualType T2,
+  ReferenceCompareResult CompareReferenceRelationship(SourceLocation Loc,
+                                                      QualType T1, QualType T2,
                                                       bool& DerivedToBase);
 
   bool CheckReferenceInit(Expr *&simpleInit_or_initList, QualType declType,

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaCXXCast.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCXXCast.cpp Thu Nov  5 07:06:35 2009
@@ -527,7 +527,8 @@
   // this is the only cast possibility, so we issue an error if we fail now.
   // FIXME: Should allow casting away constness if CStyle.
   bool DerivedToBase;
-  if (Self.CompareReferenceRelationship(SrcExpr->getType(), R->getPointeeType(),
+  if (Self.CompareReferenceRelationship(SrcExpr->getLocStart(),
+                                        SrcExpr->getType(), R->getPointeeType(),
                                         DerivedToBase) <
         Sema::Ref_Compatible_With_Added_Qualification) {
     msg = diag::err_bad_lvalue_to_rvalue_cast;

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Thu Nov  5 07:06:35 2009
@@ -3604,14 +3604,15 @@
 /// type, and the first type (T1) is the pointee type of the reference
 /// type being initialized.
 Sema::ReferenceCompareResult
-Sema::CompareReferenceRelationship(QualType T1, QualType T2,
+Sema::CompareReferenceRelationship(SourceLocation Loc, 
+                                   QualType OrigT1, QualType OrigT2,
                                    bool& DerivedToBase) {
-  assert(!T1->isReferenceType() &&
+  assert(!OrigT1->isReferenceType() &&
     "T1 must be the pointee type of the reference type");
-  assert(!T2->isReferenceType() && "T2 cannot be a reference type");
+  assert(!OrigT2->isReferenceType() && "T2 cannot be a reference type");
 
-  T1 = Context.getCanonicalType(T1);
-  T2 = Context.getCanonicalType(T2);
+  QualType T1 = Context.getCanonicalType(OrigT1);
+  QualType T2 = Context.getCanonicalType(OrigT2);
   QualType UnqualT1 = T1.getUnqualifiedType();
   QualType UnqualT2 = T2.getUnqualifiedType();
 
@@ -3621,7 +3622,9 @@
   //   T1 is a base class of T2.
   if (UnqualT1 == UnqualT2)
     DerivedToBase = false;
-  else if (IsDerivedFrom(UnqualT2, UnqualT1))
+  else if (!RequireCompleteType(Loc, OrigT1, PDiag()) &&
+           !RequireCompleteType(Loc, OrigT2, PDiag()) &&
+           IsDerivedFrom(UnqualT2, UnqualT1))
     DerivedToBase = true;
   else
     return Ref_Incompatible;
@@ -3697,7 +3700,7 @@
   Expr::isLvalueResult InitLvalue = ForceRValue ? Expr::LV_InvalidExpression :
                                                   Init->isLvalue(Context);
   ReferenceCompareResult RefRelationship
-    = CompareReferenceRelationship(T1, T2, DerivedToBase);
+    = CompareReferenceRelationship(DeclLoc, T1, T2, DerivedToBase);
 
   // Most paths end in a failed conversion.
   if (ICS)

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Thu Nov  5 07:06:35 2009
@@ -1387,8 +1387,10 @@
                                    bool AllowExplicit, bool ForceRValue,
                                    bool UserCast) {
   if (const RecordType *ToRecordType = ToType->getAs<RecordType>()) {
-    if (CXXRecordDecl *ToRecordDecl
-          = dyn_cast<CXXRecordDecl>(ToRecordType->getDecl())) {
+    if (RequireCompleteType(From->getLocStart(), ToType, PDiag())) {
+      // We're not going to find any constructors.
+    } else if (CXXRecordDecl *ToRecordDecl
+                 = dyn_cast<CXXRecordDecl>(ToRecordType->getDecl())) {
       // C++ [over.match.ctor]p1:
       //   When objects of class type are direct-initialized (8.5), or
       //   copy-initialized from an expression of the same or a

Modified: cfe/trunk/test/SemaTemplate/instantiate-complete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/instantiate-complete.cpp?rev=86129&r1=86128&r2=86129&view=diff

==============================================================================
--- cfe/trunk/test/SemaTemplate/instantiate-complete.cpp (original)
+++ cfe/trunk/test/SemaTemplate/instantiate-complete.cpp Thu Nov  5 07:06:35 2009
@@ -45,3 +45,24 @@
   (void)(p1->*pm1);
   (void)((p2->*pm2)(0));
 }
+
+// Reference binding to a base
+template<typename T>
+struct X1 { };
+
+template<typename T>
+struct X2 : public T { };
+
+void refbind_base(X2<X1<int> > &x2) {
+  X1<int> &x1 = x2;
+}
+
+// Enumerate constructors for user-defined conversion.
+template<typename T>
+struct X3 {
+  X3(T);
+};
+
+void enum_constructors(X1<float> &x1) {
+  X3<X1<float> > x3 = x1;
+}

Modified: cfe/trunk/utils/C++Tests/LLVM-Syntax/lit.local.cfg
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/C%2B%2BTests/LLVM-Syntax/lit.local.cfg?rev=86129&r1=86128&r2=86129&view=diff

==============================================================================
--- cfe/trunk/utils/C++Tests/LLVM-Syntax/lit.local.cfg (original)
+++ cfe/trunk/utils/C++Tests/LLVM-Syntax/lit.local.cfg Thu Nov  5 07:06:35 2009
@@ -16,6 +16,7 @@
                                                  pattern='^(.*\\.h|[^.]*)$',
                                                  extra_cxx_args=['-D__STDC_LIMIT_MACROS',
                                                                  '-D__STDC_CONSTANT_MACROS',
+                                                                 '-Wno-sign-compare',
                                                                  '-I%s/include' % root.llvm_src_root,
                                                                  '-I%s/include' % root.llvm_obj_root])
 





More information about the cfe-commits mailing list