]> granicus.if.org Git - clang/commitdiff
Try to instantiate templates before doing hierarchy checks in static_cast. Fixes...
authorSebastian Redl <sebastian.redl@getdesigned.at>
Thu, 22 Oct 2009 15:07:22 +0000 (15:07 +0000)
committerSebastian Redl <sebastian.redl@getdesigned.at>
Thu, 22 Oct 2009 15:07:22 +0000 (15:07 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84860 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaCXXCast.cpp
test/SemaCXX/static-cast.cpp

index c7aaa6fc67f33499a97f77673113d8f429a4765d..bf396041b473b7c931a5dbdeabd7cc30f6bc8ced 100644 (file)
@@ -175,7 +175,7 @@ Sema::ActOnCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind,
 /// DestType casts away constness as defined in C++ 5.2.11p8ff. This is used by
 /// the cast checkers.  Both arguments must denote pointer (possibly to member)
 /// types.
-bool
+static bool
 CastsAwayConstness(Sema &Self, QualType SrcType, QualType DestType) {
   // Casting away constness is defined in C++ 5.2.11p8 with reference to
   // C++ 4.4. We piggyback on Sema::IsQualificationConversion for this, since
@@ -605,6 +605,11 @@ TryCastResult
 TryStaticDowncast(Sema &Self, QualType SrcType, QualType DestType,
                   bool CStyle, const SourceRange &OpRange, QualType OrigSrcType,
                   QualType OrigDestType, unsigned &msg) {
+  // We can only work with complete types. But don't complain if it doesn't work
+  if (Self.RequireCompleteType(OpRange.getBegin(), SrcType, PDiag(0)) ||
+      Self.RequireCompleteType(OpRange.getBegin(), DestType, PDiag(0)))
+    return TC_NotApplicable;
+
   // Downcast can only happen in class hierarchies, so we need classes.
   if (!DestType->isRecordType() || !SrcType->isRecordType()) {
     return TC_NotApplicable;
index 8db8e33b93ce11b272e9e1b897465aae98573a80..d816c05e3ee3786c17de9588cff4e0f2e31e326f 100644 (file)
@@ -133,3 +133,14 @@ void t_529_9()
   (void)static_cast<int A::*>((int H::*)0); // expected-error {{ambiguous conversion from pointer to member of derived class 'struct H'}}
   (void)static_cast<int A::*>((int F::*)0); // expected-error {{conversion from pointer to member of class 'struct F'}}
 }
+
+// PR 5261 - static_cast should instantiate template if possible
+namespace pr5261 {
+  struct base {};
+  template<typename E> struct derived : public base {};
+  template<typename E> struct outer {
+    base *pb;
+    ~outer() { (void)static_cast<derived<E>*>(pb); }
+  };
+  outer<int> EntryList;
+}