]> granicus.if.org Git - clang/commitdiff
Teach code-completion for calls to be more careful with a
authorDouglas Gregor <dgregor@apple.com>
Sun, 30 May 2010 06:10:08 +0000 (06:10 +0000)
committerDouglas Gregor <dgregor@apple.com>
Sun, 30 May 2010 06:10:08 +0000 (06:10 +0000)
potentially-NULL "function" argument.

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

lib/Sema/SemaCodeComplete.cpp

index 339c46fde872e4436cee9955db1eb8159dc19c6e..0b30da5d854f2c9dfaddd439449f5c2cffed60d5 100644 (file)
@@ -2534,6 +2534,17 @@ namespace {
   };
 }
 
+static bool anyNullArguments(Expr **Args, unsigned NumArgs) {
+  if (NumArgs && !Args)
+    return true;
+  
+  for (unsigned I = 0; I != NumArgs; ++I)
+    if (!Args[I])
+      return true;
+  
+  return false;
+}
+
 void Sema::CodeCompleteCall(Scope *S, ExprTy *FnIn,
                             ExprTy **ArgsIn, unsigned NumArgs) {
   if (!CodeCompleter)
@@ -2548,7 +2559,7 @@ void Sema::CodeCompleteCall(Scope *S, ExprTy *FnIn,
   Expr **Args = (Expr **)ArgsIn;
 
   // Ignore type-dependent call expressions entirely.
-  if (Fn->isTypeDependent() || 
+  if (!Fn || Fn->isTypeDependent() || anyNullArguments(Args, NumArgs) ||
       Expr::hasAnyTypeDependentArguments(Args, NumArgs)) {
     CodeCompleteOrdinaryName(S, CCC_Expression);
     return;
@@ -2572,7 +2583,8 @@ void Sema::CodeCompleteCall(Scope *S, ExprTy *FnIn,
   else if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(NakedFn)) {
     FunctionDecl *FDecl = dyn_cast<FunctionDecl>(DRE->getDecl());
     if (FDecl) {
-      if (!FDecl->getType()->getAs<FunctionProtoType>())
+      if (!getLangOptions().CPlusPlus || 
+          !FDecl->getType()->getAs<FunctionProtoType>())
         Results.push_back(ResultCandidate(FDecl));
       else
         // FIXME: access?