Skip to content

Commit e3a7950

Browse files
committed
[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 llvm#64786. Differential Revision: https://reviews.llvm.org/D158155
1 parent 8154494 commit e3a7950

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
@@ -2472,7 +2472,7 @@ bool UnwrappedLineParser::parseParens(TokenType AmpAmpTokenType) {
24722472
const auto *PrevPrev = Prev ? Prev->getPreviousNonComment() : nullptr;
24732473
const bool Blacklisted =
24742474
PrevPrev &&
2475-
(PrevPrev->is(tok::kw___attribute) ||
2475+
(PrevPrev->isOneOf(tok::kw___attribute, tok::kw_decltype) ||
24762476
(SeenEqual &&
24772477
(PrevPrev->isOneOf(tok::kw_if, tok::kw_while) ||
24782478
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
@@ -26313,6 +26313,7 @@ TEST_F(FormatTest, RemoveParentheses) {
2631326313

2631426314
Style.RemoveParentheses = FormatStyle::RPS_MultipleParentheses;
2631526315
verifyFormat("int x __attribute__((aligned(16))) = 0;", Style);
26316+
verifyFormat("decltype((foo->bar)) baz;", Style);
2631626317
verifyFormat("class __declspec(dllimport) X {};",
2631726318
"class __declspec((dllimport)) X {};", Style);
2631826319
verifyFormat("int x = (({ 0; }));", "int x = ((({ 0; })));", Style);

0 commit comments

Comments
 (0)