[PATCH] D149643: [clang-format] Correctly limit formatted ranges when specifying qualifier alignment
Owen Pan via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu May 4 02:59:33 PDT 2023
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf3dcd3ad992c: [clang-format] Correctly limit formatted ranges when specifying qualifier… (authored by cogilvie, committed by owenpan).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D149643/new/
https://reviews.llvm.org/D149643
Files:
clang/lib/Format/QualifierAlignmentFixer.cpp
clang/unittests/Format/QualifierFixerTest.cpp
Index: clang/unittests/Format/QualifierFixerTest.cpp
===================================================================
--- clang/unittests/Format/QualifierFixerTest.cpp
+++ clang/unittests/Format/QualifierFixerTest.cpp
@@ -1343,6 +1343,29 @@
"TemplateType<Container const> t;", Style);
}
+TEST_F(QualifierFixerTest, Ranges) {
+ FormatStyle Style = getLLVMStyle();
+ Style.QualifierAlignment = FormatStyle::QAS_Custom;
+ Style.QualifierOrder = {"const", "volatile", "type"};
+
+ // Only the first line should be formatted; the second should remain as is.
+ verifyFormat("template <typename T> const Foo f();\n"
+ "template <typename T> Foo const f();",
+ "template <typename T> Foo const f();\n"
+ "template <typename T> Foo const f();",
+ Style, {tooling::Range(0, 36)});
+
+ // Only the middle line should be formatted; the first and last should remain
+ // as is.
+ verifyFormat("template <typename T> Foo const f();\n"
+ "template <typename T> const Foo f();\n"
+ "template <typename T> Foo const f();",
+ "template <typename T> Foo const f();\n"
+ "template <typename T> Foo const f();\n"
+ "template <typename T> Foo const f();",
+ Style, {tooling::Range(37, 36)});
+}
+
} // namespace
} // namespace test
} // namespace format
Index: clang/lib/Format/QualifierAlignmentFixer.cpp
===================================================================
--- clang/lib/Format/QualifierAlignmentFixer.cpp
+++ clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -587,7 +587,7 @@
assert(QualifierToken != tok::identifier && "Unrecognised Qualifier");
for (AnnotatedLine *Line : AnnotatedLines) {
- if (Line->InPPDirective)
+ if (!Line->Affected || Line->InPPDirective)
continue;
FormatToken *First = Line->First;
assert(First);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149643.519412.patch
Type: text/x-patch
Size: 1922 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230504/6dee02b4/attachment.bin>
More information about the cfe-commits
mailing list