[all-commits] [llvm/llvm-project] 0dd568: [clang][Sema] Fix assertion in `tryDiagnoseOverloa...
Alejandro Álvarez Ayllón via All-commits
all-commits at lists.llvm.org
Wed Sep 18 01:11:24 PDT 2024
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 0dd56858fe188419182a57d0e03c8cd0aa693867
https://github.com/llvm/llvm-project/commit/0dd56858fe188419182a57d0e03c8cd0aa693867
Author: Alejandro Álvarez Ayllón <alejandro.alvarez at sonarsource.com>
Date: 2024-09-18 (Wed, 18 Sep 2024)
Changed paths:
M clang/docs/ReleaseNotes.rst
M clang/lib/Sema/SemaCast.cpp
A clang/test/Parser/cxx-bad-cast-diagnose-broken-template.cpp
Log Message:
-----------
[clang][Sema] Fix assertion in `tryDiagnoseOverloadedCast` (#108021)
Fixed an assertion failure in debug mode, and potential crashes in
release mode, when
diagnosing a failed cast caused indirectly by a failed implicit
conversion to the type of the constructor parameter.
For instance
```
template<typename>
struct StringTrait {};
template< int N >
struct StringTrait< const char[ N ] > {
typedef char CharType;
static const MissingIntT length = N - 1;
};
class String {
public:
template <typename T>
String(T& str, typename StringTrait<T>::CharType = 0);
};
class Exception {
public:
Exception(String const&);
};
void foo() {
throw Exception("some error");
}
```
`Exception(String const&)` is a matching constructor for `Exception`
from a `const char*`, via an implicit conversion to `String`. However,
the instantiation of the `String` constructor will fail because of the
missing type `MissingIntT` inside the specialization of `StringTrait`.
When trying to emit a diagnosis, `tryDiagnoseOverloadedCast` expects not
to have a matching constructor, but there is; it just could not be
instantiated.
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list