https://github.com/ChuanqiXu9 created https://github.com/llvm/llvm-project/pull/129212
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. >From 8876ef70a08f8547d49b89275a3b1b455221abd0 Mon Sep 17 00:00:00 2001 From: Chuanqi Xu <yedeng...@linux.alibaba.com> Date: Fri, 28 Feb 2025 17:03:49 +0800 Subject: [PATCH] [C++20] [Modules] Support generating in-class defined function with try-catch body 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. --- clang/lib/Parse/ParseCXXInlineMethods.cpp | 5 +++++ clang/test/Modules/try-func-body.cppm | 13 +++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 clang/test/Modules/try-func-body.cppm 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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits