diff options
author | Anders Carlsson <andersca@mac.com> | 2009-08-25 14:12:34 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-08-25 14:12:34 +0000 |
commit | be96bc94e880dc319439ff783c90edd04b11b287 (patch) | |
tree | 47f3dd52b72a6b8aeba5677484b885bd352465a0 /clang/lib | |
parent | 114056f22c060f8978c403a094fd95c76962e17e (diff) | |
download | bcm5719-llvm-be96bc94e880dc319439ff783c90edd04b11b287.tar.gz bcm5719-llvm-be96bc94e880dc319439ff783c90edd04b11b287.zip |
Handle the implicit 'this' parameter for format attributes.
llvm-svn: 79987
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Sema/SemaDeclAttr.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index af0f03d2d9f..c6a5241f94d 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -1222,9 +1222,6 @@ static void HandleFormatAttr(Decl *d, const AttributeList &Attr, Sema &S) { return; } - // FIXME: in C++ the implicit 'this' function parameter also counts. this is - // needed in order to be compatible with GCC the index must start in 1 and the - // limit is numargs+1 unsigned NumArgs = getFunctionOrMethodNumArgs(d); unsigned FirstIdx = 1; @@ -1271,6 +1268,16 @@ static void HandleFormatAttr(Decl *d, const AttributeList &Attr, Sema &S) { return; } + // FIXME: We should handle the implicit 'this' parameter in a more generic + // way that can be used for other arguments. + bool HasImplicitThisParam = false; + if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(d)) { + if (MD->isInstance()) { + HasImplicitThisParam = true; + NumArgs++; + } + } + if (Idx.getZExtValue() < FirstIdx || Idx.getZExtValue() > NumArgs) { S.Diag(Attr.getLoc(), diag::err_attribute_argument_out_of_bounds) << "format" << 2 << IdxExpr->getSourceRange(); @@ -1280,6 +1287,8 @@ static void HandleFormatAttr(Decl *d, const AttributeList &Attr, Sema &S) { // FIXME: Do we need to bounds check? unsigned ArgIdx = Idx.getZExtValue() - 1; + if (HasImplicitThisParam) ArgIdx--; + // make sure the format string is really a string QualType Ty = getFunctionOrMethodArgType(d, ArgIdx); |