summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format/FormatTest.cpp
diff options
context:
space:
mode:
authorpaulhoad <mydeveloperday@gmail.com>2019-11-06 09:34:01 +0000
committerpaulhoad <mydeveloperday@gmail.com>2019-11-06 09:34:48 +0000
commit76ec6b1ef69fcbd27cb0d587a5eb2d51a135a6bb (patch)
tree87e2f352250478e90e738645b2e0e57217909a41 /clang/unittests/Format/FormatTest.cpp
parent1a6903bdfeca5facfc0c595e7cf9a14f0e87fb0e (diff)
downloadbcm5719-llvm-76ec6b1ef69fcbd27cb0d587a5eb2d51a135a6bb.tar.gz
bcm5719-llvm-76ec6b1ef69fcbd27cb0d587a5eb2d51a135a6bb.zip
[clang-format] [PR35518] C++17 deduction guides are wrongly formatted
Summary: see https://bugs.llvm.org/show_bug.cgi?id=35518 clang-format removes spaces around deduction guides but not trailing return types, make the consistent ``` template <typename T> S(T)->S<T>; auto f(int, int) -> double; ``` becomes ``` template <typename T> S(T) -> S<T>; auto f(int, int) -> double; ``` Reviewers: klimek, mitchell-stellar, owenpan, sammccall, lichray, curdeius, KyrBoh Reviewed By: curdeius Subscribers: merge_guards_bot, hans, lichray, cfe-commits Tags: #clang-format, #clang-tools-extra, #clang Differential Revision: https://reviews.llvm.org/D69577
Diffstat (limited to 'clang/unittests/Format/FormatTest.cpp')
-rw-r--r--clang/unittests/Format/FormatTest.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index ea03ee1c3cc..eacb389400b 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -4977,6 +4977,29 @@ TEST_F(FormatTest, TrailingReturnType) {
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)>;");
+ verifyFormat("template <class T> A() -> A<decltype(p->foo<3>())>;");
+ verifyFormat("template <class T> A() -> A<decltype(foo<traits<1>>)>;");
+ verifyFormat("template <class T> A() -> A<sizeof(p->foo<1>)>;");
+ verifyFormat("template <class T> A() -> A<(3 < 2)>;");
+ verifyFormat("template <class T> A() -> A<((3) < (2))>;");
+ verifyFormat("template <class T> x() -> x<1>;");
+ verifyFormat("template <class T> explicit x(T &) -> x<1>;");
+
+ // Ensure not deduction guides.
+ verifyFormat("c()->f<int>();");
+ verifyFormat("x()->foo<1>;");
+ verifyFormat("x = p->foo<3>();");
+ verifyFormat("x()->x<1>();");
+ verifyFormat("x()->x<1>;");
+}
+
TEST_F(FormatTest, BreaksFunctionDeclarationsWithTrailingTokens) {
// Avoid breaking before trailing 'const' or other trailing annotations, if
// they are not function-like.
OpenPOWER on IntegriCloud