[cfe-commits] r146430 - in /cfe/trunk: lib/Sema/SemaChecking.cpp test/SemaCXX/Inputs/array-bounds-system-header.h test/SemaCXX/array-bounds-system-header.cpp

Matt Beaumont-Gay matthewbg at google.com
Mon Dec 12 14:57:06 PST 2011


Argyrios, a couple of questions came up while I was working on this
patch, and Chandler suggested you were the right person to ask:

On Mon, Dec 12, 2011 at 14:35, Matt Beaumont-Gay <matthewbg at google.com> wrote:
> @@ -4381,6 +4381,16 @@
>     switch (expr->getStmtClass()) {
>       case Stmt::ArraySubscriptExprClass: {
>         const ArraySubscriptExpr *ASE = cast<ArraySubscriptExpr>(expr);
> +        // Suppress the warning if the subscript expression (as identified by
> +        // the ']' location) and the index expression are both from macro
> +        // expansions within a system header.
> +        SourceLocation RBracketLoc = SourceMgr.getSpellingLoc(
> +            ASE->getRBracketLoc());
> +        SourceLocation IndexLoc = SourceMgr.getSpellingLoc(
> +            ASE->getIdx()->IgnoreParens()->getLocStart());
> +        if (SourceMgr.isFromSameFile(RBracketLoc, IndexLoc) &&
> +            SourceMgr.isInSystemHeader(RBracketLoc))

It might be nice to tighten this check down to check whether the
subscript expression and the index expression come from the same
macro. Is there an API for this? I didn't see anything obvious in
SourceManager.

> Added: cfe/trunk/test/SemaCXX/Inputs/array-bounds-system-header.h

I tried to test this by faking up a system header with line directives
in an existing test file, but it looks like isFromSameFile doesn't
respect line directives. Is this a bug or a feature?

Thanks,
Matt




More information about the cfe-commits mailing list