Skip to content

Commit 1440745

Browse files
owencatru
authored andcommitted
[clang-format] Exclude kw_decltype in RemoveParentheses
From https://en.cppreference.com/w/cpp/language/decltype: Note that if the name of an object is parenthesized, it is treated as an ordinary lvalue expression, thus decltype(x) and decltype((x)) are often different types. Fixes #64786. Differential Revision: https://reviews.llvm.org/D158155 (cherry picked from commit e3a7950)
1 parent 6f1974e commit 1440745

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

clang/lib/Format/UnwrappedLineParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2465,7 +2465,7 @@ bool UnwrappedLineParser::parseParens(TokenType AmpAmpTokenType) {
24652465
const auto *PrevPrev = Prev ? Prev->getPreviousNonComment() : nullptr;
24662466
const bool Blacklisted =
24672467
PrevPrev &&
2468-
(PrevPrev->is(tok::kw___attribute) ||
2468+
(PrevPrev->isOneOf(tok::kw___attribute, tok::kw_decltype) ||
24692469
(SeenEqual &&
24702470
(PrevPrev->isOneOf(tok::kw_if, tok::kw_while) ||
24712471
PrevPrev->endsSequence(tok::kw_constexpr, tok::kw_if))));

clang/unittests/Format/FormatTest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26268,6 +26268,7 @@ TEST_F(FormatTest, RemoveParentheses) {
2626826268

2626926269
Style.RemoveParentheses = FormatStyle::RPS_MultipleParentheses;
2627026270
verifyFormat("int x __attribute__((aligned(16))) = 0;", Style);
26271+
verifyFormat("decltype((foo->bar)) baz;", Style);
2627126272
verifyFormat("class __declspec(dllimport) X {};",
2627226273
"class __declspec((dllimport)) X {};", Style);
2627326274
verifyFormat("int x = (({ 0; }));", "int x = ((({ 0; })));", Style);

0 commit comments

Comments
 (0)