[clang] Fix assertion failure during operator overload resolution. (PR #98671)
Daniel M. Katz via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 12 11:04:54 PDT 2024
https://github.com/katzdm created https://github.com/llvm/llvm-project/pull/98671
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.
>From 9c15b7828f2aec1cd2ffd61141f1be544e2f1f61 Mon Sep 17 00:00:00 2001
From: Dan Katz <katzdm at gmail.com>
Date: Fri, 12 Jul 2024 13:57:33 -0400
Subject: [PATCH] Fix assertion failure during operator overload resolution.
---
clang/lib/Sema/SemaConcept.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
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;
More information about the cfe-commits
mailing list