[clang] efa8783 - [NFC] Add unittest for inline functions in modules
Chuanqi Xu via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 15 22:36:01 PDT 2022
Author: Chuanqi Xu
Date: 2022-08-16T13:35:38+08:00
New Revision: efa8783290d81689054d47bf71de452134bf4910
URL: https://github.com/llvm/llvm-project/commit/efa8783290d81689054d47bf71de452134bf4910
DIFF: https://github.com/llvm/llvm-project/commit/efa8783290d81689054d47bf71de452134bf4910.diff
LOG: [NFC] Add unittest for inline functions in modules
Added:
Modified:
clang/unittests/AST/DeclTest.cpp
Removed:
################################################################################
diff --git a/clang/unittests/AST/DeclTest.cpp b/clang/unittests/AST/DeclTest.cpp
index f651f36f1344f..7fe715db52979 100644
--- a/clang/unittests/AST/DeclTest.cpp
+++ b/clang/unittests/AST/DeclTest.cpp
@@ -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());
+}
+
More information about the cfe-commits
mailing list