r259681 - [Sema debugger support] Require non-void types to be complete in unknown-anytype casts.

Douglas Gregor via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 3 11:13:08 PST 2016


Author: dgregor
Date: Wed Feb  3 13:13:08 2016
New Revision: 259681

URL: http://llvm.org/viewvc/llvm-project?rev=259681&view=rev
Log:
[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.

Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/SemaCXX/unknown-anytype.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=259681&r1=259680&r2=259681&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Feb  3 13:13:08 2016
@@ -14478,6 +14478,12 @@ ExprResult RebuildUnknownAnyExpr::resolv
 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();

Modified: cfe/trunk/test/SemaCXX/unknown-anytype.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/unknown-anytype.cpp?rev=259681&r1=259680&r2=259681&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/unknown-anytype.cpp (original)
+++ cfe/trunk/test/SemaCXX/unknown-anytype.cpp Wed Feb  3 13:13:08 2016
@@ -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<typename T> struct X; // expected-note{{template is declared here}}
+
+  extern __unknown_anytype test0(...);
+
+  void test() {
+    (X<int>)test0(); // expected-error{{implicit instantiation of undefined template 'test5::X<int>'}}
+  }
+}




More information about the cfe-commits mailing list