MyDeveloperDay updated this revision to Diff 227062. MyDeveloperDay added a reviewer: lichray. MyDeveloperDay added a comment.
Detect deduction guides arrow as a TrailingReturn arrow, allowing use of existing space before/after rules CHANGES SINCE LAST ACTION https://reviews.llvm.org/D69577/new/ https://reviews.llvm.org/D69577 Files: clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/FormatTest.cpp Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -4977,6 +4977,15 @@ verifyFormat("void f() { auto a = b->c(); }"); } +TEST_F(FormatTest, DeductionGuides) { + verifyFormat("template <class T> A(const T &, const T &) -> A<T &>;"); + verifyFormat("template <class T> explicit A(T &, T &&) -> A<T>;"); + verifyFormat("template <class... Ts> S(Ts...) -> S<Ts...>;"); + verifyFormat( + "template <class... T>\n" + "array(T &&... t) -> array<std::common_type_t<T...>, sizeof...(T)>;"); +} + TEST_F(FormatTest, BreaksFunctionDeclarationsWithTrailingTokens) { // Avoid breaking before trailing 'const' or other trailing annotations, if // they are not function-like. Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -1397,6 +1397,10 @@ !Current.Previous->is(tok::kw_operator)) { // not auto operator->() -> xxx; Current.Type = TT_TrailingReturnArrow; + } else if (Current.Previous && Current.Previous->is(tok::r_paren) && + Current.startsSequence(tok::arrow, tok::identifier, tok::less)) { + // Deduction guides trailing arrow "...) -> A<T>". + Current.Type = TT_TrailingReturnArrow; } else if (Current.isOneOf(tok::star, tok::amp, tok::ampamp)) { Current.Type = determineStarAmpUsage(Current, Contexts.back().CanBeExpression &&
Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -4977,6 +4977,15 @@ verifyFormat("void f() { auto a = b->c(); }"); } +TEST_F(FormatTest, DeductionGuides) { + verifyFormat("template <class T> A(const T &, const T &) -> A<T &>;"); + verifyFormat("template <class T> explicit A(T &, T &&) -> A<T>;"); + verifyFormat("template <class... Ts> S(Ts...) -> S<Ts...>;"); + verifyFormat( + "template <class... T>\n" + "array(T &&... t) -> array<std::common_type_t<T...>, sizeof...(T)>;"); +} + TEST_F(FormatTest, BreaksFunctionDeclarationsWithTrailingTokens) { // Avoid breaking before trailing 'const' or other trailing annotations, if // they are not function-like. Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -1397,6 +1397,10 @@ !Current.Previous->is(tok::kw_operator)) { // not auto operator->() -> xxx; Current.Type = TT_TrailingReturnArrow; + } else if (Current.Previous && Current.Previous->is(tok::r_paren) && + Current.startsSequence(tok::arrow, tok::identifier, tok::less)) { + // Deduction guides trailing arrow "...) -> A<T>". + Current.Type = TT_TrailingReturnArrow; } else if (Current.isOneOf(tok::star, tok::amp, tok::ampamp)) { Current.Type = determineStarAmpUsage(Current, Contexts.back().CanBeExpression &&
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits