From 0fc3a001682c0bd076a329024192e57b3bc950fd Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Wed, 3 Feb 2016 19:13:08 +0000 Subject: [PATCH] [Sema debugger support] Require non-void types to be complete in unknown-anytype casts. When performing a cast from an __unknown_anytype function call to a non-void type, we need to make sure that type is complete. Fixes rdar://problem/23959960. llvm-svn: 259681 --- clang/lib/Sema/SemaExpr.cpp | 6 ++++++ clang/test/SemaCXX/unknown-anytype.cpp | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index b7d494fa..dc63879 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -14478,6 +14478,12 @@ ExprResult RebuildUnknownAnyExpr::resolveDecl(Expr *E, ValueDecl *VD) { ExprResult Sema::checkUnknownAnyCast(SourceRange TypeRange, QualType CastType, Expr *CastExpr, CastKind &CastKind, ExprValueKind &VK, CXXCastPath &Path) { + // The type we're casting to must be either void or complete. + if (!CastType->isVoidType() && + RequireCompleteType(TypeRange.getBegin(), CastType, + diag::err_typecheck_cast_to_incomplete)) + return ExprError(); + // Rewrite the casted expression from scratch. ExprResult result = RebuildUnknownAnyExpr(*this, CastType).Visit(CastExpr); if (!result.isUsable()) return ExprError(); diff --git a/clang/test/SemaCXX/unknown-anytype.cpp b/clang/test/SemaCXX/unknown-anytype.cpp index a07ec83..95ad040 100644 --- a/clang/test/SemaCXX/unknown-anytype.cpp +++ b/clang/test/SemaCXX/unknown-anytype.cpp @@ -45,3 +45,14 @@ namespace test4 { int x = (int) test1; // expected-error {{function 'test1' with unknown type must be given a function type}} } } + +// rdar://problem/23959960 +namespace test5 { + template struct X; // expected-note{{template is declared here}} + + extern __unknown_anytype test0(...); + + void test() { + (X)test0(); // expected-error{{implicit instantiation of undefined template 'test5::X'}} + } +} -- 2.7.4