diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp @@ -59,7 +59,11 @@ unless(hasParent(arraySubscriptExpr())), unless(hasParentIgnoringImpCasts(explicitCastExpr())), unless(isInsideOfRangeBeginEndStmt()), - unless(hasSourceExpression(ignoringParens(stringLiteral())))) + unless(hasSourceExpression(ignoringParens(stringLiteral()))), + unless(hasSourceExpression(ignoringParens( + conditionalOperator(allOf( + hasTrueExpression(stringLiteral()), + hasFalseExpression(stringLiteral()))))))) .bind("cast")), this); } diff --git a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-bounds-array-to-pointer-decay.cpp b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-bounds-array-to-pointer-decay.cpp --- a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-bounds-array-to-pointer-decay.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-bounds-array-to-pointer-decay.cpp @@ -49,3 +49,14 @@ void *a[2]; f2(static_cast(a)); // OK, explicit cast } + +void issue31155(int i) { + const char *a = i ? "foo" : "bar"; // OK, decay string literal to pointer + const char *b = i ? "foo" : "foobar"; // OK, decay string literal to pointer + + char arr[1]; + const char *c = i ? arr : "bar"; + // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: do not implicitly decay an array into a pointer + const char *d = i ? "foo" : arr; + // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: do not implicitly decay an array into a pointer +}