[llvm-branch-commits] [clang] release/19.x: [C++20] [Modules] Treat constexpr/consteval member function as implicitly inline (PR #109076)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Sep 17 19:43:05 PDT 2024
https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/109076
Backport 74ac96ae1a81c7ecc0e27ff6f45309cff1f2df97
Requested by: @ChuanqiXu9
>From 26d5adcf1b4b9930db2a0f17257a66756557cbfb Mon Sep 17 00:00:00 2001
From: Chuanqi Xu <yedeng.yd at linux.alibaba.com>
Date: Mon, 9 Sep 2024 11:23:47 +0800
Subject: [PATCH] [C++20] [Modules] Treat constexpr/consteval member function
as implicitly inline
Close https://github.com/llvm/llvm-project/issues/107673
(cherry picked from commit 74ac96ae1a81c7ecc0e27ff6f45309cff1f2df97)
---
clang/lib/Sema/SemaDecl.cpp | 1 +
clang/test/Modules/pr107673.cppm | 12 ++++++++++++
2 files changed, 13 insertions(+)
create mode 100644 clang/test/Modules/pr107673.cppm
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index d608dd92a4b479..d3c07d0a76f12e 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -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
index 00000000000000..dc66c9ac2245b3
--- /dev/null
+++ b/clang/test/Modules/pr107673.cppm
@@ -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
More information about the llvm-branch-commits
mailing list