https://github.com/pb01ka created https://github.com/llvm/llvm-project/pull/226722
In this PR, I have added a regression test in `clang/test/SemaCXX/deduced-return-type-cxx14.cpp` for the issue reported in https://github.com/llvm/llvm-project/issues/46331. Here's a complete reasoning behind my change, - I executed a `git bisect` session between `llvmorg-19-init` and `llvmorg-20-init`. The commands used to initiate the session are as follows, ```sh git bisect start --term-old=crashes --term-new=fixed git bisect crashes llvmorg-19-init git bisect fixed llvmorg-20-init ``` The final output is as follows, ```sh eb08c0f1659d12524f58a01bf174177b8acedf2e is the first fixed commit commit eb08c0f1659d12524f58a01bf174177b8acedf2e Author: Krystian Stasiowski <[email protected]> Date: Tue Apr 2 08:35:42 2024 -0400 [Clang][Sema] Fix explicit specializations of member function templates with a deduced return type (#86817) . . . ``` - Upon investigation of https://github.com/llvm/llvm-project/pull/86817/changes/e84e4b6fedb5a643082cd38d0e10d910b299f73f (part of https://github.com/llvm/llvm-project/pull/86817) in accordance with the tracebacks reported in [this](https://github.com/llvm/llvm-project/issues/46331#issue-1077271655) and [this](https://github.com/llvm/llvm-project/issues/46331#issue-1077271655) comment I found that, - Inside `ActOnFunctionDeclarator`, the `Context.getFunctionType(Result, FPT->getParamTypes(), FPT->getExtProtoInfo())` call inside `NewFD->setType(...)` leads to, - `return getFunctionTypeInternal(ResultTy, Args, EPI, false);` in `clang/include/clang/AST/ASTContext.h` and hence the crash. - Now it is worth noting that the above commit moves the entire `if (getLangOpts().CPlusPlus14 && ...` from `ActOnFunctionDeclarator` block into `CheckFunctionDeclaration`. Therefore I think the crash got fixed as a side effect of this movement. - I observed the presence of `getLangOpts().CPlusPlus14` and hence I tried out the reproducer with clang 18 using both C++11 and C++14 flags, - C++11: The crash never happens. The compiler reports the errors and exits. See [here](https://godbolt.org/z/vohjahYTv) (please set C++11 in `Std version` under 🔧 option, the code re-runs for me without this setting whenever I open the link). - C++14: The crash does happen. See [here](https://godbolt.org/z/ha5zq5eKW). - As a consequence of above findings I decided to add the regression test in `clang/test/SemaCXX/deduced-return-type-cxx14.cpp` instead of `clang/test/SemaCXX/trailing-return-0x.cpp` because the latter file only tests on C++11 in which setting the crash would never happen. In addition to this, the fixing commit also added its test in `deduced-return-type-cxx14.cpp` (C++14 onwards enabled). Please let me know if you find any incorrectness in my investigation/decisions. TY. Closes https://github.com/llvm/llvm-project/issues/46331 >From 6d29b452dbbcbc7a14d3e0bee9ba23e52b05f221 Mon Sep 17 00:00:00 2001 From: pb01ka <[email protected]> Date: Sat, 26 Sep 2026 22:45:29 +0530 Subject: [PATCH] [clang] Add regression test for #46331 clang/test/SemaCXX/deduced-return-type-cxx14.cpp was chosen over clang/test/SemaCXX/trailing-return-0x.cpp for adding the regression test because the crash which #46331 reported only happened with C++14 onwards where as trailing-return-0x.cpp is tested only with C++11. --- clang/test/SemaCXX/deduced-return-type-cxx14.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/clang/test/SemaCXX/deduced-return-type-cxx14.cpp b/clang/test/SemaCXX/deduced-return-type-cxx14.cpp index 10ea9e82f5327..f91335a76feac 100644 --- a/clang/test/SemaCXX/deduced-return-type-cxx14.cpp +++ b/clang/test/SemaCXX/deduced-return-type-cxx14.cpp @@ -792,3 +792,10 @@ auto f() { return c; } } + +namespace GH46331 { +template <typename> alignas (enum a{}) // expected-error {{cannot be defined in a type specifier}} +~a ()()() -> auto; // expected-error {{function with trailing return type must specify return type 'auto', not 'void'}} \ + // expected-error {{destructor must be a non-static member function}} \ + // expected-error {{destructor cannot be declared as a template}} +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
