rymiel created this revision. rymiel added reviewers: MyDeveloperDay, curdeius, HazardyKnusperkeks, owenpan. Herald added a project: All. rymiel requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Previously, the formatter would refuse to treat identifiers within a compound `concept` definition as actually part of the definition, if they were after the negation operator `!`. It is now made consistent with the likes of `&&` and `||`. Fixes https://github.com/llvm/llvm-project/issues/55898 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D131978 Files: clang/lib/Format/UnwrappedLineParser.cpp clang/unittests/Format/FormatTest.cpp Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -24109,6 +24109,15 @@ "concept DelayedCheck = false || requires(T t) { t.bar(); } && " "sizeof(T) <= 8;"); + verifyFormat("template <typename T>\n" + "concept DelayedCheck = Unit<T> && !DerivedUnit<T>;"); + + verifyFormat("template <typename T>\n" + "concept DelayedCheck = Unit<T> && !(DerivedUnit<T>);"); + + verifyFormat("template <typename T>\n" + "concept DelayedCheck = Unit<T> && !!DerivedUnit<T>;"); + verifyFormat("template <typename T>\n" "concept DelayedCheck = !!false || requires(T t) { t.bar(); } " "&& sizeof(T) <= 8;"); Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -3537,7 +3537,8 @@ switch (FormatTok->Previous->Tok.getKind()) { case tok::coloncolon: // Nested identifier. case tok::ampamp: // Start of a function or variable for the - case tok::pipepipe: // constraint expression. + case tok::pipepipe: // constraint expression. (binary) + case tok::exclaim: // The same as above, but unary. case tok::kw_requires: // Initial identifier of a requires clause. case tok::equal: // Initial identifier of a concept declaration. break;
Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -24109,6 +24109,15 @@ "concept DelayedCheck = false || requires(T t) { t.bar(); } && " "sizeof(T) <= 8;"); + verifyFormat("template <typename T>\n" + "concept DelayedCheck = Unit<T> && !DerivedUnit<T>;"); + + verifyFormat("template <typename T>\n" + "concept DelayedCheck = Unit<T> && !(DerivedUnit<T>);"); + + verifyFormat("template <typename T>\n" + "concept DelayedCheck = Unit<T> && !!DerivedUnit<T>;"); + verifyFormat("template <typename T>\n" "concept DelayedCheck = !!false || requires(T t) { t.bar(); } " "&& sizeof(T) <= 8;"); Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -3537,7 +3537,8 @@ switch (FormatTok->Previous->Tok.getKind()) { case tok::coloncolon: // Nested identifier. case tok::ampamp: // Start of a function or variable for the - case tok::pipepipe: // constraint expression. + case tok::pipepipe: // constraint expression. (binary) + case tok::exclaim: // The same as above, but unary. case tok::kw_requires: // Initial identifier of a requires clause. case tok::equal: // Initial identifier of a concept declaration. break;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits