This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rGfce3eed9f93a: [clang-format][c++2b] support removal of the space between auto and {} in… (authored by MyDeveloperDay).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D113826/new/ https://reviews.llvm.org/D113826 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 @@ -22566,6 +22566,30 @@ EXPECT_EQ(Code, format(Code, Style)); } +TEST_F(FormatTest, FormatDecayCopy) { + // error cases from unit tests + verifyFormat("foo(auto())"); + verifyFormat("foo(auto{})"); + verifyFormat("foo(auto({}))"); + verifyFormat("foo(auto{{}})"); + + verifyFormat("foo(auto(1))"); + verifyFormat("foo(auto{1})"); + verifyFormat("foo(new auto(1))"); + verifyFormat("foo(new auto{1})"); + verifyFormat("decltype(auto(1)) x;"); + verifyFormat("decltype(auto{1}) x;"); + verifyFormat("auto(x);"); + verifyFormat("auto{x};"); + verifyFormat("new auto{x};"); + verifyFormat("auto{x} = y;"); + verifyFormat("auto(x) = y;"); // actually a declaration, but this is clearly + // the user's own fault + verifyFormat("integral auto(x) = y;"); // actually a declaration, but this is + // clearly the user's own fault + verifyFormat("auto(*p)() = f;"); // actually a declaration; TODO FIXME +} + } // namespace } // namespace format } // namespace clang Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -2940,6 +2940,10 @@ return true; } + // auto{x} auto(x) + if (Left.is(tok::kw_auto) && Right.isOneOf(tok::l_paren, tok::l_brace)) + return false; + // requires clause Concept1<T> && Concept2<T> if (Left.is(TT_ConstraintJunctions) && Right.is(tok::identifier)) return true;
Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -22566,6 +22566,30 @@ EXPECT_EQ(Code, format(Code, Style)); } +TEST_F(FormatTest, FormatDecayCopy) { + // error cases from unit tests + verifyFormat("foo(auto())"); + verifyFormat("foo(auto{})"); + verifyFormat("foo(auto({}))"); + verifyFormat("foo(auto{{}})"); + + verifyFormat("foo(auto(1))"); + verifyFormat("foo(auto{1})"); + verifyFormat("foo(new auto(1))"); + verifyFormat("foo(new auto{1})"); + verifyFormat("decltype(auto(1)) x;"); + verifyFormat("decltype(auto{1}) x;"); + verifyFormat("auto(x);"); + verifyFormat("auto{x};"); + verifyFormat("new auto{x};"); + verifyFormat("auto{x} = y;"); + verifyFormat("auto(x) = y;"); // actually a declaration, but this is clearly + // the user's own fault + verifyFormat("integral auto(x) = y;"); // actually a declaration, but this is + // clearly the user's own fault + verifyFormat("auto(*p)() = f;"); // actually a declaration; TODO FIXME +} + } // namespace } // namespace format } // namespace clang Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -2940,6 +2940,10 @@ return true; } + // auto{x} auto(x) + if (Left.is(tok::kw_auto) && Right.isOneOf(tok::l_paren, tok::l_brace)) + return false; + // requires clause Concept1<T> && Concept2<T> if (Left.is(TT_ConstraintJunctions) && Right.is(tok::identifier)) return true;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits