[clang] [clang-format] Handle constrained auto in QualifierAlignment (PR #72251)
https://github.com/owenca created https://github.com/llvm/llvm-project/pull/72251 Fixed #69610. >From 8e61a470fc7e4cf11a6cf285668a7f9eca72702c Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Tue, 14 Nov 2023 05:05:14 -0800 Subject: [PATCH] [clang-format] Handle constrained auto in QualifierAlignment Fixed #69610. --- clang/lib/Format/QualifierAlignmentFixer.cpp | 5 + clang/unittests/Format/QualifierFixerTest.cpp | 10 ++ 2 files changed, 15 insertions(+) diff --git a/clang/lib/Format/QualifierAlignmentFixer.cpp b/clang/lib/Format/QualifierAlignmentFixer.cpp index 7167e50ec724eab..72464d367153934 100644 --- a/clang/lib/Format/QualifierAlignmentFixer.cpp +++ b/clang/lib/Format/QualifierAlignmentFixer.cpp @@ -345,6 +345,8 @@ const FormatToken *LeftRightQualifierAlignmentFixer::analyzeRight( TypeToken = Next->getNextNonComment()->getNextNonComment(); } } +if (Next->is(tok::kw_auto)) + TypeToken = Next; // Place the Qualifier at the end of the list of qualifiers. while (isQualifier(TypeToken->getNextNonComment())) { @@ -446,6 +448,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 const> P;\n#if 0\n#else\n#endif", "Foo> 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> P;\n#if 0\n#else\n#endif", "Foo const> P;\n#if 0\n#else\n#endif", Style); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Handle constrained auto in QualifierAlignment (PR #72251)
llvmbot wrote: @llvm/pr-subscribers-clang-format Author: Owen Pan (owenca) Changes Fixed #69610. --- Full diff: https://github.com/llvm/llvm-project/pull/72251.diff 2 Files Affected: - (modified) clang/lib/Format/QualifierAlignmentFixer.cpp (+5) - (modified) clang/unittests/Format/QualifierFixerTest.cpp (+10) ``diff diff --git a/clang/lib/Format/QualifierAlignmentFixer.cpp b/clang/lib/Format/QualifierAlignmentFixer.cpp index 7167e50ec724eab..72464d367153934 100644 --- a/clang/lib/Format/QualifierAlignmentFixer.cpp +++ b/clang/lib/Format/QualifierAlignmentFixer.cpp @@ -345,6 +345,8 @@ const FormatToken *LeftRightQualifierAlignmentFixer::analyzeRight( TypeToken = Next->getNextNonComment()->getNextNonComment(); } } +if (Next->is(tok::kw_auto)) + TypeToken = Next; // Place the Qualifier at the end of the list of qualifiers. while (isQualifier(TypeToken->getNextNonComment())) { @@ -446,6 +448,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 const> P;\n#if 0\n#else\n#endif", "Foo> 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> P;\n#if 0\n#else\n#endif", "Foo const> P;\n#if 0\n#else\n#endif", Style); `` https://github.com/llvm/llvm-project/pull/72251 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Handle constrained auto in QualifierAlignment (PR #72251)
https://github.com/rymiel approved this pull request. A hooray for getting rid of invalid-code-generation https://github.com/llvm/llvm-project/pull/72251 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Handle constrained auto in QualifierAlignment (PR #72251)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/72251 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Handle constrained auto in QualifierAlignment (PR #72251)
@@ -345,6 +345,8 @@ const FormatToken *LeftRightQualifierAlignmentFixer::analyzeRight( TypeToken = Next->getNextNonComment()->getNextNonComment(); } } +if (Next->is(tok::kw_auto)) owenca wrote: ```suggestion if (Next->is(tok::kw_auto)) ``` https://github.com/llvm/llvm-project/pull/72251 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Handle constrained auto in QualifierAlignment (PR #72251)
https://github.com/owenca edited https://github.com/llvm/llvm-project/pull/72251 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Handle constrained auto in QualifierAlignment (PR #72251)
https://github.com/owenca updated https://github.com/llvm/llvm-project/pull/72251 >From 8e61a470fc7e4cf11a6cf285668a7f9eca72702c Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Tue, 14 Nov 2023 05:05:14 -0800 Subject: [PATCH 1/2] [clang-format] Handle constrained auto in QualifierAlignment Fixed #69610. --- clang/lib/Format/QualifierAlignmentFixer.cpp | 5 + clang/unittests/Format/QualifierFixerTest.cpp | 10 ++ 2 files changed, 15 insertions(+) diff --git a/clang/lib/Format/QualifierAlignmentFixer.cpp b/clang/lib/Format/QualifierAlignmentFixer.cpp index 7167e50ec724eab..72464d367153934 100644 --- a/clang/lib/Format/QualifierAlignmentFixer.cpp +++ b/clang/lib/Format/QualifierAlignmentFixer.cpp @@ -345,6 +345,8 @@ const FormatToken *LeftRightQualifierAlignmentFixer::analyzeRight( TypeToken = Next->getNextNonComment()->getNextNonComment(); } } +if (Next->is(tok::kw_auto)) + TypeToken = Next; // Place the Qualifier at the end of the list of qualifiers. while (isQualifier(TypeToken->getNextNonComment())) { @@ -446,6 +448,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 const> P;\n#if 0\n#else\n#endif", "Foo> 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> P;\n#if 0\n#else\n#endif", "Foo const> P;\n#if 0\n#else\n#endif", Style); >From 0a5a39d757400328f95ad5a851c9d247bdc8321b Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Tue, 14 Nov 2023 15:33:34 -0800 Subject: [PATCH 2/2] Update clang/lib/Format/QualifierAlignmentFixer.cpp --- clang/lib/Format/QualifierAlignmentFixer.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/clang/lib/Format/QualifierAlignmentFixer.cpp b/clang/lib/Format/QualifierAlignmentFixer.cpp index 72464d367153934..e2fab1c1e3c2a37 100644 --- a/clang/lib/Format/QualifierAlignmentFixer.cpp +++ b/clang/lib/Format/QualifierAlignmentFixer.cpp @@ -345,6 +345,7 @@ const FormatToken *LeftRightQualifierAlignmentFixer::analyzeRight( TypeToken = Next->getNextNonComment()->getNextNonComment(); } } + if (Next->is(tok::kw_auto)) TypeToken = Next; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Handle constrained auto in QualifierAlignment (PR #72251)
https://github.com/owenca closed https://github.com/llvm/llvm-project/pull/72251 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits