[NFC] Add unittest for inline functions in modules
authorChuanqi Xu <yedeng.yd@linux.alibaba.com>
Tue, 16 Aug 2022 05:33:53 +0000 (13:33 +0800)
committerChuanqi Xu <yedeng.yd@linux.alibaba.com>
Tue, 16 Aug 2022 05:35:38 +0000 (13:35 +0800)
clang/unittests/AST/DeclTest.cpp

index f651f36..7fe715d 100644 (file)
@@ -279,3 +279,35 @@ TEST(Decl, GetNonTransparentDeclContext) {
 
   EXPECT_TRUE(f->getNonTransparentDeclContext()->isFileContext());
 }
+
+TEST(Decl, MemberFunctionInModules) {
+  llvm::Annotations Code(R"(
+    module;
+    class G {
+      void bar() {}
+    };
+    export module M;
+    class A {
+      void foo() {}
+    };
+    )");
+
+  auto AST =
+      tooling::buildASTFromCodeWithArgs(Code.code(), /*Args=*/{"-std=c++20"});
+  ASTContext &Ctx = AST->getASTContext();
+
+  auto *foo = selectFirst<FunctionDecl>(
+      "foo", match(functionDecl(hasName("foo")).bind("foo"), Ctx));
+
+  // The function defined within a class definition is not implicitly inline
+  // if it is not attached to global module
+  EXPECT_FALSE(foo->isInlined());
+
+  auto *bar = selectFirst<FunctionDecl>(
+      "bar", match(functionDecl(hasName("bar")).bind("bar"), Ctx));
+
+  // In global module, the function defined within a class definition is
+  // implicitly inline.
+  EXPECT_TRUE(bar->isInlined());
+}
+