[clang] [clang-format] Allow decltype in requires clause (PR #78847)

Owen Pan via cfe-commits cfe-commits at lists.llvm.org
Sun Jan 21 20:44:09 PST 2024


================
@@ -1071,6 +1071,37 @@ TEST_F(TokenAnnotatorTest, UnderstandsRequiresClausesAndConcepts) {
                     "concept C = (!Foo<T>) && Bar;");
   ASSERT_EQ(Tokens.size(), 19u) << Tokens;
   EXPECT_TOKEN(Tokens[15], tok::ampamp, TT_BinaryOperator);
+
+  Tokens = annotate("void f() & requires(C<decltype(x)>) {}");
+  ASSERT_EQ(Tokens.size(), 18u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::amp, TT_PointerOrReference);
+  EXPECT_TOKEN(Tokens[5], tok::kw_requires, TT_RequiresClause);
+
+  Tokens = annotate("auto f() -> int& requires(C<decltype(x)>) {}");
+  ASSERT_EQ(Tokens.size(), 20u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::amp, TT_PointerOrReference);
+  EXPECT_TOKEN(Tokens[7], tok::kw_requires, TT_RequiresClause);
+
+  Tokens = annotate("int foo(auto t) {\n"
+                    "    if (requires (decltype(t) x) {x.foo();}) {\n"
+                    "        return 1;\n"
+                    "    }\n"
+                    "    return 0;\n"
+                    "}\n");
----------------
owenca wrote:

Do we need the newline?

https://github.com/llvm/llvm-project/pull/78847


More information about the cfe-commits mailing list