[llvm-branch-commits] [clang] 1440745 - [clang-format] Exclude kw_decltype in RemoveParentheses
Tobias Hieta via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Aug 30 08:08:39 PDT 2023
Author: Owen Pan
Date: 2023-08-30T17:00:56+02:00
New Revision: 1440745b0a641205a6db6e99e68723c52d1c582b
URL: https://github.com/llvm/llvm-project/commit/1440745b0a641205a6db6e99e68723c52d1c582b
DIFF: https://github.com/llvm/llvm-project/commit/1440745b0a641205a6db6e99e68723c52d1c582b.diff
LOG: [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 e3a79503a30f8c9d8fba79f3e5427bb895f320cf)
Added:
Modified:
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index 28e2954b5bebaf..852437b9390fc7 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -2465,7 +2465,7 @@ bool UnwrappedLineParser::parseParens(TokenType AmpAmpTokenType) {
const auto *PrevPrev = Prev ? Prev->getPreviousNonComment() : nullptr;
const bool Blacklisted =
PrevPrev &&
- (PrevPrev->is(tok::kw___attribute) ||
+ (PrevPrev->isOneOf(tok::kw___attribute, tok::kw_decltype) ||
(SeenEqual &&
(PrevPrev->isOneOf(tok::kw_if, tok::kw_while) ||
PrevPrev->endsSequence(tok::kw_constexpr, tok::kw_if))));
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index ed0c5e64f44743..271778b5bb9e6c 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -26268,6 +26268,7 @@ TEST_F(FormatTest, RemoveParentheses) {
Style.RemoveParentheses = FormatStyle::RPS_MultipleParentheses;
verifyFormat("int x __attribute__((aligned(16))) = 0;", Style);
+ verifyFormat("decltype((foo->bar)) baz;", Style);
verifyFormat("class __declspec(dllimport) X {};",
"class __declspec((dllimport)) X {};", Style);
verifyFormat("int x = (({ 0; }));", "int x = ((({ 0; })));", Style);
More information about the llvm-branch-commits
mailing list