This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Accept string literal decay in conditional operator
ClosedPublic

Authored by estan on Jan 7 2022, 8:31 AM.

Details

Summary

The cppcoreguidelines-pro-bounds-array-to-pointer-decay check currently accepts

const char *b = i ? "foo" : "foobar";

but not

const char *a = i ? "foo" : "bar";

This is because the AST is slightly different in the latter case (see https://godbolt.org/z/MkHVvs).

This eliminates the inconsistency by making it accept the latter form as well.

Fixes https://github.com/llvm/llvm-project/issues/31155.

Diff Detail

Event Timeline

estan created this revision.Jan 7 2022, 8:31 AM
estan edited the summary of this revision. (Show Details)Jan 7 2022, 8:37 AM
estan edited the summary of this revision. (Show Details)
estan edited the summary of this revision. (Show Details)Jan 7 2022, 8:40 AM
estan edited the summary of this revision. (Show Details)
estan updated this revision to Diff 398165.Jan 7 2022, 8:51 AM

Format code with git-clang-format

estan published this revision for review.Jan 7 2022, 9:07 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 7 2022, 9:07 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
estan updated this revision to Diff 398177.Jan 7 2022, 9:29 AM

Add entry in clang-tools-extra/docs/ReleaseNotes.rst

estan edited the summary of this revision. (Show Details)Jan 7 2022, 9:33 AM
estan retitled this revision from Accept string literal decay in conditional operator to [clang-tidy] Accept string literal decay in conditional operator.Jan 9 2022, 3:20 AM
aaron.ballman accepted this revision.Jan 11 2022, 5:06 AM

LGTM, thanks!

This revision is now accepted and ready to land.Jan 11 2022, 5:06 AM
estan added a comment.Jan 11 2022, 9:44 AM

Thanks @aaron.ballman. I don't have commit/push rights, so someone please commit for me when you got the time.

Thanks @aaron.ballman. I don't have commit/push rights, so someone please commit for me when you got the time.

Happy to! What name and email address would you like me to use for patch attribution?

Ah right, Elvis Stansvik <elvstone@gmail.com>

Thank you for the fix! I commit on your behalf in 36af07334246a87a0f3fb9bbc85dedfca04b00d1.

BTW how are backports to release branches made in LLVM? (sorry if it's in the docs somewhere!)

BTW how are backports to release branches made in LLVM? (sorry if it's in the docs somewhere!)

We document the process here: https://llvm.org/docs/HowToReleaseLLVM.html#merge-requests, but it could be pretty late to make it to 13.0.1.

estan added a comment.Jan 11 2022, 1:13 PM

Ah thanks. Yea no worries.