[cfe-commits] r84860 - in /cfe/trunk: lib/Sema/SemaCXXCast.cpp test/SemaCXX/static-cast.cpp
Sebastian Redl
sebastian.redl at getdesigned.at
Thu Oct 22 08:07:23 PDT 2009
Author: cornedbee
Date: Thu Oct 22 10:07:22 2009
New Revision: 84860
URL: http://llvm.org/viewvc/llvm-project?rev=84860&view=rev
Log:
Try to instantiate templates before doing hierarchy checks in static_cast. Fixes PR5261.
Modified:
cfe/trunk/lib/Sema/SemaCXXCast.cpp
cfe/trunk/test/SemaCXX/static-cast.cpp
Modified: cfe/trunk/lib/Sema/SemaCXXCast.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCXXCast.cpp?rev=84860&r1=84859&r2=84860&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCXXCast.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCXXCast.cpp Thu Oct 22 10:07:22 2009
@@ -175,7 +175,7 @@
/// 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 @@
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;
Modified: cfe/trunk/test/SemaCXX/static-cast.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/static-cast.cpp?rev=84860&r1=84859&r2=84860&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/static-cast.cpp (original)
+++ cfe/trunk/test/SemaCXX/static-cast.cpp Thu Oct 22 10:07:22 2009
@@ -133,3 +133,14 @@
(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;
+}
More information about the cfe-commits
mailing list