[clang] [clang][Sema] Add regression test for #46331 (PR #226722)

via cfe-commits cfe-commits at lists.llvm.org
Sat Sep 26 11:03:07 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: pb01ka

<details>
<summary>Changes</summary>

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 <sdkrystian@<!-- -->gmail.com>
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

---
Full diff: https://github.com/llvm/llvm-project/pull/226722.diff


1 Files Affected:

- (modified) clang/test/SemaCXX/deduced-return-type-cxx14.cpp (+7) 


``````````diff
diff --git a/clang/test/SemaCXX/deduced-return-type-cxx14.cpp b/clang/test/SemaCXX/deduced-return-type-cxx14.cpp
index 10ea9e82f5327f..f91335a76feac8 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}}
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/226722


More information about the cfe-commits mailing list