diff options
-rw-r--r-- | include/clang/Basic/DiagnosticSemaKinds.td | 1 | ||||
-rw-r--r-- | lib/Sema/SemaCXXCast.cpp | 8 | ||||
-rw-r--r-- | test/SemaCXX/static-cast-complete-type.cpp | 13 |
3 files changed, 22 insertions, 0 deletions
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 1aa8420649..4917598180 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -1515,6 +1515,7 @@ def err_bad_static_cast_pointer_nonpointer : Error< "cannot cast from type %1 to pointer type %2">; def err_bad_static_cast_member_pointer_nonmp : Error< "cannot cast from type %1 to member pointer type %2">; +def err_bad_static_cast_incomplete : Error<"%0 is an incomplete type">; // These messages don't adhere to the pattern. // FIXME: Display the path somehow better. diff --git a/lib/Sema/SemaCXXCast.cpp b/lib/Sema/SemaCXXCast.cpp index d88bbebec1..ceb2de7ae8 100644 --- a/lib/Sema/SemaCXXCast.cpp +++ b/lib/Sema/SemaCXXCast.cpp @@ -759,6 +759,14 @@ TryStaticImplicitCast(Sema &Self, Expr *SrcExpr, QualType DestType, bool CStyle, const SourceRange &OpRange, unsigned &msg, CXXMethodDecl *&ConversionDecl) { + if (DestType->isRecordType()) { + if (Self.RequireCompleteType(OpRange.getBegin(), DestType, + diag::err_bad_dynamic_cast_incomplete)) { + msg = 0; + return TC_Failed; + } + } + if (DestType->isReferenceType()) { // At this point of CheckStaticCast, if the destination is a reference, // this has to work. There is no other way that works. diff --git a/test/SemaCXX/static-cast-complete-type.cpp b/test/SemaCXX/static-cast-complete-type.cpp new file mode 100644 index 0000000000..83583a5adf --- /dev/null +++ b/test/SemaCXX/static-cast-complete-type.cpp @@ -0,0 +1,13 @@ +// RUN: clang-cc -fsyntax-only -verify %s +template<typename T> struct S { + S(int); +}; + +struct T; // expected-note{{forward declaration of 'struct T'}} + +void f() { + S<int> s0 = static_cast<S<int> >(0); + S<void*> s1 = static_cast<S<void*> >(00); + + (void)static_cast<T>(10); // expected-error{{'struct T' is an incomplete type}} +} |