diff options
| author | Douglas Gregor <dgregor@apple.com> | 2011-07-30 08:57:03 +0000 |
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2011-07-30 08:57:03 +0000 |
| commit | 5ff4e98c61257844aeaef539483842264ee3e974 (patch) | |
| tree | 0c52bc671264c20a8bc3ff5c6e34cb1c544c8df2 /clang/lib/Sema/SemaExpr.cpp | |
| parent | b58053bb41bb21901314ce91d7d7bd6acbe75b0f (diff) | |
| download | bcm5719-llvm-5ff4e98c61257844aeaef539483842264ee3e974.tar.gz bcm5719-llvm-5ff4e98c61257844aeaef539483842264ee3e974.zip | |
Introduce a Fix-It for the "missing sentinel" warning, adding an
appropriate sentinel at the end of the argument list. Also, put the
sentinel warnings under -Wsentinel. Fixes <rdar://problem/8764236>.
llvm-svn: 136566
Diffstat (limited to 'clang/lib/Sema/SemaExpr.cpp')
| -rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 966fcbffcf2..43e3807e21d 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -156,13 +156,9 @@ void Sema::DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc, if (!attr) return; - // FIXME: In C++0x, if any of the arguments are parameter pack - // expansions, we can't check for the sentinel now. int sentinelPos = attr->getSentinel(); int nullPos = attr->getNullPos(); - // FIXME. ObjCMethodDecl and FunctionDecl need be derived from the same common - // base class. Then we won't be needing two versions of the same code. unsigned int i = 0; bool warnNotEnoughArgs = false; int isMethod = 0; @@ -247,7 +243,22 @@ void Sema::DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc, // Unfortunately, __null has type 'int'. if (isa<GNUNullExpr>(sentinelExpr)) return; - Diag(Loc, diag::warn_missing_sentinel) << isMethod; + SourceLocation MissingNilLoc + = PP.getLocForEndOfToken(sentinelExpr->getLocEnd()); + std::string NullValue; + if (isMethod && PP.getIdentifierInfo("nil")->hasMacroDefinition()) + NullValue = "nil"; + else if (PP.getIdentifierInfo("NULL")->hasMacroDefinition()) + NullValue = "NULL"; + else if (Context.getTypeSize(Context.IntTy) + == Context.getTypeSize(Context.getSizeType())) + NullValue = "0"; + else + NullValue = "0L"; + + Diag(MissingNilLoc, diag::warn_missing_sentinel) + << isMethod + << FixItHint::CreateInsertion(MissingNilLoc, ", " + NullValue); Diag(D->getLocation(), diag::note_sentinel_here) << isMethod; } |

