[clang] [C++20] [Modules] Support generating in-class defined function with try-catch body (PR #129212)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 28 01:12:22 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Chuanqi Xu (ChuanqiXu9)
<details>
<summary>Changes</summary>
See the example:
```
export module func;
class C {
public:
void member() try {
} catch (...) {
}
};
```
We woudln't generate the definition for `C::member` but we should. Since the function is non-inline in modules.
This turns out to be an oversight in parser to me. Since the try-catch body is relatively rare, so maybe we just forgot it.
---
Full diff: https://github.com/llvm/llvm-project/pull/129212.diff
2 Files Affected:
- (modified) clang/lib/Parse/ParseCXXInlineMethods.cpp (+5)
- (added) clang/test/Modules/try-func-body.cppm (+13)
``````````diff
diff --git a/clang/lib/Parse/ParseCXXInlineMethods.cpp b/clang/lib/Parse/ParseCXXInlineMethods.cpp
index 6c01af55ef3c4..723ebfa59fc03 100644
--- a/clang/lib/Parse/ParseCXXInlineMethods.cpp
+++ b/clang/lib/Parse/ParseCXXInlineMethods.cpp
@@ -632,6 +632,11 @@ void Parser::ParseLexedMethodDef(LexedMethod &LM) {
if (Tok.is(tok::eof) && Tok.getEofData() == LM.D)
ConsumeAnyToken();
+
+ if (auto *FD = dyn_cast_or_null<FunctionDecl>(LM.D))
+ if (isa<CXXMethodDecl>(FD) ||
+ FD->isInIdentifierNamespace(Decl::IDNS_OrdinaryFriend))
+ Actions.ActOnFinishInlineFunctionDef(FD);
return;
}
if (Tok.is(tok::colon)) {
diff --git a/clang/test/Modules/try-func-body.cppm b/clang/test/Modules/try-func-body.cppm
new file mode 100644
index 0000000000000..379f5e47f4f8e
--- /dev/null
+++ b/clang/test/Modules/try-func-body.cppm
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -std=c++20 %s -fexceptions -fcxx-exceptions -emit-llvm -triple %itanium_abi_triple -o - | FileCheck %s
+
+export module func;
+class C {
+public:
+ void member() try {
+
+ } catch (...) {
+
+ }
+};
+
+// CHECK: define {{.*}}@_ZNW4func1C6memberEv
``````````
</details>
https://github.com/llvm/llvm-project/pull/129212
More information about the cfe-commits
mailing list