]> granicus.if.org Git - clang/commitdiff
[Sema] Call CheckParmForFunctionDef on ObjC method parameters
authorReid Kleckner <reid@kleckner.net>
Mon, 24 Jun 2013 14:38:26 +0000 (14:38 +0000)
committerReid Kleckner <reid@kleckner.net>
Mon, 24 Jun 2013 14:38:26 +0000 (14:38 +0000)
CheckParmForFunctionDef performs standard checks for type completeness
and other things like a destructor check for the MSVC++ ABI.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@184740 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Sema/Sema.h
lib/Sema/SemaChecking.cpp
lib/Sema/SemaDeclObjC.cpp
test/SemaObjC/method-bad-param.m
test/SemaObjCXX/microsoft-abi-byval.mm [new file with mode: 0644]

index 71e2aaf5de4bffbbc5851bf67c29e4e071550b54..82de36908cd9152dd1fd2ad537770d4ab20cdbbb 100644 (file)
@@ -2244,7 +2244,8 @@ public:
                            CallExpr *CE, FunctionDecl *FD);
 
   /// Helpers for dealing with blocks and functions.
-  bool CheckParmsForFunctionDef(ParmVarDecl **Param, ParmVarDecl **ParamEnd,
+  bool CheckParmsForFunctionDef(ParmVarDecl *const *Param,
+                                ParmVarDecl *const *ParamEnd,
                                 bool CheckParameterNames);
   void CheckCXXDefaultArguments(FunctionDecl *FD);
   void CheckExtraCXXDefaultArguments(Declarator &D);
index 163d5fe849b153be0fee7915394b5f0b4d5add99..996f20cc91bb5dce39aac21f2f998f64e301c60d 100644 (file)
@@ -5758,7 +5758,8 @@ void Sema::CheckBitFieldInitialization(SourceLocation InitLoc,
 /// takes care of any checks that cannot be performed on the
 /// declaration itself, e.g., that the types of each of the function
 /// parameters are complete.
-bool Sema::CheckParmsForFunctionDef(ParmVarDecl **P, ParmVarDecl **PEnd,
+bool Sema::CheckParmsForFunctionDef(ParmVarDecl *const *P,
+                                    ParmVarDecl *const *PEnd,
                                     bool CheckParameterNames) {
   bool HasInvalidParm = false;
   for (; P != PEnd; ++P) {
index 8ce4ef3e4bb31121bc81228b185378c98a06f479..a818d37459ed7dfd2499c30359aafeb77026dc7e 100644 (file)
@@ -324,14 +324,14 @@ void Sema::ActOnStartOfObjCMethodDef(Scope *FnBodyScope, Decl *D) {
   PushOnScopeChains(MDecl->getSelfDecl(), FnBodyScope);
   PushOnScopeChains(MDecl->getCmdDecl(), FnBodyScope);
 
+  // The ObjC parser requires parameter names so there's no need to check.
+  CheckParmsForFunctionDef(MDecl->param_begin(), MDecl->param_end(),
+                           /*CheckParameterNames=*/false);
+
   // Introduce all of the other parameters into this scope.
   for (ObjCMethodDecl::param_iterator PI = MDecl->param_begin(),
        E = MDecl->param_end(); PI != E; ++PI) {
     ParmVarDecl *Param = (*PI);
-    if (!Param->isInvalidDecl() &&
-        RequireCompleteType(Param->getLocation(), Param->getType(),
-                            diag::err_typecheck_decl_incomplete_type))
-          Param->setInvalidDecl();
     if (!Param->isInvalidDecl() &&
         getLangOpts().ObjCAutoRefCount &&
         !HasExplicitOwnershipAttr(*this, Param))
index 30aba7b9d0de7d5da0e425221f920a8eef589688..ad67a34edb00c3ebedbac1e197adc36aa1931dfa 100644 (file)
@@ -46,3 +46,13 @@ enum bogus; // expected-note {{forward declaration of 'enum bogus'}}
 - (int[6])arrayRet; // expected-error {{function cannot return array type 'int [6]'}}
 - (int())funcRet; // expected-error {{function cannot return function type 'int ()'}}
 @end
+
+@interface qux
+- (void) my_method: (int)arg; // expected-note {{method 'my_method:' declared here}}
+@end
+
+// FIXME: The diagnostic and recovery here could probably be improved.
+@implementation qux // expected-warning {{method definition for 'my_method:' not found}}
+- (void) my_method: (int) { // expected-error {{expected identifier}}
+}
+@end
diff --git a/test/SemaObjCXX/microsoft-abi-byval.mm b/test/SemaObjCXX/microsoft-abi-byval.mm
new file mode 100644 (file)
index 0000000..f0c4caa
--- /dev/null
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -cxx-abi microsoft -Wno-objc-root-class %s
+
+class Foo {
+  ~Foo(); // expected-note {{implicitly declared private here}}
+};
+
+@interface bar
+- (void) my_method: (Foo)arg;
+@end
+
+@implementation bar
+- (void) my_method: (Foo)arg { // expected-error {{variable of type 'Foo' has private destructor}}
+}
+@end