Index: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp =================================================================== --- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp +++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp @@ -45,9 +45,12 @@ if (!getLangOpts().CPlusPlus) return; + // Note: if a struct contains an array member, the compiler-generated + // constructor has an arraySubscriptExpr. Finder->addMatcher(arraySubscriptExpr(hasBase(ignoringImpCasts(hasType( constantArrayType().bind("type")))), - hasIndex(expr().bind("index"))) + hasIndex(expr().bind("index")), + unless(hasAncestor(isImplicit()))) .bind("expr"), this); Index: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-constant-array-index.cpp =================================================================== --- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-constant-array-index.cpp +++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-constant-array-index.cpp @@ -74,3 +74,14 @@ int i = 0; s[i] = 3; // OK, custom operator } + +struct A { + // The compiler-generated copy constructor uses an ArraySubscriptExpr. Don't warn. + int x[3]; +}; + +void use_A() { + // Force the compiler to generate a copy constructor. + A a; + A a2(a); +}