This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Access checks not done classes derived of std::array
ClosedPublic

Authored by sousajo on Jul 30 2023, 11:10 AM.

Details

Summary

Index accessing checks are not performed for derived classes of
of std::array, as only std::array itself and its aliases
seems to be checked.

This patch aims to extend it for derived classes such as:

template<class T, size_t N>
class DerivedArray : public std::array<T, N> {};

Diff Detail

Event Timeline

sousajo created this revision.Jul 30 2023, 11:10 AM
sousajo requested review of this revision.Jul 30 2023, 11:10 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 30 2023, 11:10 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
sousajo edited the summary of this revision. (Show Details)Jul 30 2023, 11:11 AM
sousajo added a reviewer: PiotrZSL.

Good, just verify that documentation for this check is still proper, and add entry in release notes about this change.

This revision is now accepted and ready to land.Jul 30 2023, 12:13 PM

hi @PiotrZSL, thanks for the review :) can you please land it for me?

Jorge Pinto Sousa <jorge.pinto.sousa@proton.me>

carlosgalvezp added a comment.EditedJul 30 2023, 12:20 PM

What about the use case of privately inheriting std::array, and overriding the operator[] there with bounds check? I believe there shouldn't be warnings there.

Would it be possible to check only _public_ inheritance?

PiotrZSL set the repository for this revision to rG LLVM Github Monorepo.Jul 30 2023, 12:22 PM

Good, just verify that documentation for this check is still proper, and add entry in release notes about this change.

I missed those, I will sure ^^

What about the use case of privately inheriting std::array, and overriding the operator[] there with bounds check? I believe there shouldn't be warnings there.

Would it be possible to check only _public_ inheritance?

Good point, I cannot think of an _easy_ way to check it.

Good point, I cannot think of an _easy_ way to check it.

I think you can do something like this:

Finder->addMatcher(
    cxxOperatorCallExpr(
        hasOverloadedOperatorName("[]"),
        calle(cxxMethodDecl(ofClass(cxxRecordDecl(hasName("::std::array")).bind("type"))))
        hasArgument(1, expr().bind("index")))
        .bind("expr"),
    this);

In such case instead of checking argument passed to call, we check what operator we used and who provided it.

sousajo updated this revision to Diff 553062.Aug 24 2023, 3:35 AM

@PiotrZSL @carlosgalvezp can you please recheck?

PiotrZSL set the repository for this revision to rG LLVM Github Monorepo.Aug 24 2023, 3:37 AM

thanks for the review. can you please land it for me pls? Jorge Pinto Sousa <jorge.pinto.sousa@proton.me>