This is an archive of the discontinued LLVM Phabricator instance.

Fix bug 25362 "cppcoreguidelines-pro-bounds-array-to-pointer-decay does not consider const"
ClosedPublic

Authored by mgehre on Nov 9 2015, 2:40 PM.

Details

Summary

The current matcher is

implicitCastExpr(unless(hasParent(explicitCastExpr())))

but the AST in the bug is

`-CXXStaticCastExpr 0x2bb64f8 <col:21, col:55> 'void *const *'

static_cast<void *const *> <NoOp>

`-ImplicitCastExpr 0x2bb64e0 <col:47> 'void *const *' <NoOp>
  `-ImplicitCastExpr 0x2bb64c8 <col:47> 'void **'

<ArrayToPointerDecay>

`-DeclRefExpr 0x2bb6458 <col:47> 'void *[2]' lvalue Var

0x2bb59d0 'addrlist' 'void *[2]'
i.e. an ImplicitCastExpr (const cast) between decay and explicit cast.

Diff Detail

Repository
rL LLVM

Event Timeline

mgehre updated this revision to Diff 39756.Nov 9 2015, 2:40 PM
mgehre retitled this revision from to Fix bug 25362 "cppcoreguidelines-pro-bounds-array-to-pointer-decay does not consider const".
mgehre updated this object.
mgehre added a subscriber: cfe-commits.
aaron.ballman edited edge metadata.Nov 10 2015, 5:29 AM

I generally think this LGTM, but I would wait for a second confirmation before committing.

clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
33 ↗(On Diff #39756)

const auto *E, please.

alexfh accepted this revision.Nov 10 2015, 6:08 AM
alexfh edited edge metadata.

Looks good with a couple of comments. Thank you for the fix!

clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
33 ↗(On Diff #39756)

It's not immediately clear what type auto hides here. Please make it the concrete type instead. Same for auto Parents below.

I think, auto should be used, when the initializer contains the concrete type literally, or when the type is difficult to reproduce exactly, or specifying it doesn't add any clearness to the code (e.g. in for (auto I = some_container.begin(); ...) using SomeContainerType<...>::iterator instead of auto doesn't make code easier to read or understand).

test/clang-tidy/cppcoreguidelines-pro-bounds-array-to-pointer-decay.cpp
45 ↗(On Diff #39756)

The function name and the variable name above don't add any value here. I'd shorten them to 1-2 character placeholders.

This revision is now accepted and ready to land.Nov 10 2015, 6:08 AM
mgehre updated this revision to Diff 39948.Nov 11 2015, 11:09 AM
mgehre edited edge metadata.

Update for review comments

This revision was automatically updated to reflect the committed changes.