[C++20] [Modules] Treat constexpr/consteval member function as implicitly inline
authorChuanqi Xu <yedeng.yd@linux.alibaba.com>
Mon, 9 Sep 2024 03:23:47 +0000 (11:23 +0800)
committerTobias Hieta <tobias@hieta.se>
Tue, 24 Sep 2024 06:29:23 +0000 (08:29 +0200)
Close https://github.com/llvm/llvm-project/issues/107673

(cherry picked from commit 74ac96ae1a81c7ecc0e27ff6f45309cff1f2df97)

clang/lib/Sema/SemaDecl.cpp
clang/test/Modules/pr107673.cppm [new file with mode: 0644]

index d608dd92a4b479fc0962fc664e696db5cbd441f5..d3c07d0a76f12efcf1497b893ca7da108afe01fc 100644 (file)
@@ -9732,6 +9732,7 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
     // the function decl is created above).
     // FIXME: We need a better way to separate C++ standard and clang modules.
     bool ImplicitInlineCXX20 = !getLangOpts().CPlusPlusModules ||
+                               NewFD->isConstexpr() || NewFD->isConsteval() ||
                                !NewFD->getOwningModule() ||
                                NewFD->isFromExplicitGlobalModule() ||
                                NewFD->getOwningModule()->isHeaderLikeModule();
diff --git a/clang/test/Modules/pr107673.cppm b/clang/test/Modules/pr107673.cppm
new file mode 100644 (file)
index 0000000..dc66c9a
--- /dev/null
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -std=c++20 %s -ast-dump | FileCheck %s
+export module a;
+export class f {
+public:
+    void non_inline_func() {}
+    constexpr void constexpr_func() {}
+    consteval void consteval_func() {}
+};
+
+// CHECK-NOT: non_inline_func {{.*}}implicit-inline
+// CHECK: constexpr_func {{.*}}implicit-inline
+// CHECK: consteval_func {{.*}}implicit-inline