[clang] b04664b - [clang-format] Handle constrained auto in QualifierAlignment (#72251)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 15 14:28:42 PST 2023
Author: Owen Pan
Date: 2023-11-15T14:28:37-08:00
New Revision: b04664be6f484551ba34e5e34c511e77d5af709a
URL: https://github.com/llvm/llvm-project/commit/b04664be6f484551ba34e5e34c511e77d5af709a
DIFF: https://github.com/llvm/llvm-project/commit/b04664be6f484551ba34e5e34c511e77d5af709a.diff
LOG: [clang-format] Handle constrained auto in QualifierAlignment (#72251)
Fixed #69610.
Added:
Modified:
clang/lib/Format/QualifierAlignmentFixer.cpp
clang/unittests/Format/QualifierFixerTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/QualifierAlignmentFixer.cpp b/clang/lib/Format/QualifierAlignmentFixer.cpp
index 7167e50ec724eab..e2fab1c1e3c2a37 100644
--- a/clang/lib/Format/QualifierAlignmentFixer.cpp
+++ b/clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -346,6 +346,9 @@ const FormatToken *LeftRightQualifierAlignmentFixer::analyzeRight(
}
}
+ if (Next->is(tok::kw_auto))
+ TypeToken = Next;
+
// Place the Qualifier at the end of the list of qualifiers.
while (isQualifier(TypeToken->getNextNonComment())) {
// The case `volatile Foo::iter const` -> `Foo::iter const volatile`
@@ -446,6 +449,9 @@ const FormatToken *LeftRightQualifierAlignmentFixer::analyzeLeft(
return false;
}
+ if (Tok->endsSequence(tok::kw_auto, tok::identifier))
+ return false;
+
return true;
};
diff --git a/clang/unittests/Format/QualifierFixerTest.cpp b/clang/unittests/Format/QualifierFixerTest.cpp
index 73814e7414f5e7d..a56323a88f4a04d 100644
--- a/clang/unittests/Format/QualifierFixerTest.cpp
+++ b/clang/unittests/Format/QualifierFixerTest.cpp
@@ -352,6 +352,11 @@ TEST_F(QualifierFixerTest, RightQualifier) {
verifyFormat("auto const &ir = i;", "const auto &ir = i;", Style);
verifyFormat("auto const *ip = &i;", "const auto *ip = &i;", Style);
+ verifyFormat("void f(Concept auto const &x);",
+ "void f(const Concept auto &x);", Style);
+ verifyFormat("void f(std::integral auto const &x);",
+ "void f(const std::integral auto &x);", Style);
+
verifyFormat("Foo<Foo<int> const> P;\n#if 0\n#else\n#endif",
"Foo<const Foo<int>> P;\n#if 0\n#else\n#endif", Style);
@@ -653,6 +658,11 @@ TEST_F(QualifierFixerTest, LeftQualifier) {
verifyFormat("const auto &ir = i;", "auto const &ir = i;", Style);
verifyFormat("const auto *ip = &i;", "auto const *ip = &i;", Style);
+ verifyFormat("void f(const Concept auto &x);",
+ "void f(Concept auto const &x);", Style);
+ verifyFormat("void f(const std::integral auto &x);",
+ "void f(std::integral auto const &x);", Style);
+
verifyFormat("Foo<const Foo<int>> P;\n#if 0\n#else\n#endif",
"Foo<Foo<int> const> P;\n#if 0\n#else\n#endif", Style);
More information about the cfe-commits
mailing list