[clang] Fix assertion failure during conversion function overload resolution. (PR #98671)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 12 11:16:42 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Daniel M. Katz (katzdm)
<details>
<summary>Changes</summary>
When clang is built with assertions, an otherwise silent (and seemingly innocuous) assertion failure from `SemaConcept.cpp` is triggered by the following program:
```cpp
struct S {
operator int();
template <typename T> operator T();
};
constexpr auto r = &S::operator int;
```
The function in question compares the "constrained-ness" of `S::operator int` and `S::operator T<int>`; the template kind of the former is `TK_NonTemplate`, whereas the template kind of the later is `TK_FunctionTemplateSpecialization`. The later kind is not "expected" by the function, thus the assertion-failure.
---
Full diff: https://github.com/llvm/llvm-project/pull/98671.diff
2 Files Affected:
- (modified) clang/lib/Sema/SemaConcept.cpp (+2-1)
- (added) clang/test/SemaCXX/PR98671.cpp (+14)
``````````diff
diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 202dd86c67f62..f94fb8be20e07 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -1519,7 +1519,8 @@ bool Sema::IsAtLeastAsConstrained(NamedDecl *D1,
auto IsExpectedEntity = [](const FunctionDecl *FD) {
FunctionDecl::TemplatedKind Kind = FD->getTemplatedKind();
return Kind == FunctionDecl::TK_NonTemplate ||
- Kind == FunctionDecl::TK_FunctionTemplate;
+ Kind == FunctionDecl::TK_FunctionTemplate ||
+ Kind == FunctionDecl::TK_FunctionTemplateSpecialization;
};
const auto *FD2 = dyn_cast<FunctionDecl>(D2);
(void)IsExpectedEntity;
diff --git a/clang/test/SemaCXX/PR98671.cpp b/clang/test/SemaCXX/PR98671.cpp
new file mode 100644
index 0000000000000..696b750759854
--- /dev/null
+++ b/clang/test/SemaCXX/PR98671.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only %s -verify
+
+struct S {
+ operator int();
+
+ template <typename T>
+ operator T();
+};
+
+
+// Ensure that no assertion is raised when overload resolution fails while
+// choosing between an operator function template and an operator function.
+constexpr auto r = &S::operator int;
+// expected-error at -1 {{initializer of type '<overloaded function type>'}}
``````````
</details>
https://github.com/llvm/llvm-project/pull/98671
More information about the cfe-commits
mailing list