-
Notifications
You must be signed in to change notification settings - Fork 10.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clang] CTAD deduces alias template that does not satisfy the condition of the alias template #85192
Comments
Probably related to #84492 , not sure whether this is a duplicate. |
@llvm/issue-subscribers-clang-frontend Author: Imple Lee (ImpleLee)
The following code snippet fails `static_assert`, and the type of `i2` is inferred to be (as reported in the diagnostic message) `std::array<std::array<int, 3>, 1>`, which does not even constitute a legal `my_ints`.
Godbolt link: https://godbolt.org/z/1Mo9hz4W7 . #include <array>
#include <type_traits>
template <int N>
using my_ints = std::array<int, N>;
int main() {
my_ints i = {1, 2, 3};
my_ints i2 = {i};
static_assert(std::is_same_v<decltype(i2), decltype(i)>);
// error: static assertion failed due to requirement 'std::is_same_v<std::array<std::array<int, 3>, 1>, std::array<int, 3>>'
} |
A more simple demo: #include <array>
#include <type_traits>
template <std::size_t N>
using ints = std::array<int, N>;
ints m = {1., 2.};
static_assert(std::is_same_v<decltype(m), ints<2>>);
// error: static assertion failed due to requirement 'std::is_same_v<std::array<double, 2>, std::array<int, 2>>' |
template <typename T>
struct A {
T data;
};
using A_int = A<int>;
// A_int a = {1.0}; // error: type 'double' cannot be narrowed to 'int' in initializer list [-Wc++11-narrowing]
template <typename=void>
using A2_int = A<int>;
A2_int a2 = {1.0}; // passing |
I think it is a symptom of missing the is_deducible constraint for the synthesized deduction guides, #84492. A simplified case
When deducing template arguments for
The function argument is Ideally, And 2) should not be viable as well (gcc has the correct behavior), because we can not deduce the template argument of the alias |
I can accept this explanation, and that does solve my question. I am okay if you choose to close this issue as duplicate, or just leave it open until you have implemented the |
…templates. Fixes llvm#85192 Fixes llvm#84492
…templates. Fixes llvm#85192 Fixes llvm#84492
…templates. Fixes llvm#85192 Fixes llvm#84492
…templates. Fixes llvm#85192 Fixes llvm#84492
…templates. Fixes llvm#85192 Fixes llvm#84492 - rebase to main - add release note for __is_deducible - implement diagnostics for bad argument types for __is_deducible Don't expose __is_deducible trait. Refine the implementation of hiding __is_deducible type trait. Apply approach 3.
…templates. Fixes llvm#85192 Fixes llvm#84492 - rebase to main - add release note for __is_deducible - implement diagnostics for bad argument types for __is_deducible Don't expose __is_deducible trait. Refine the implementation of hiding __is_deducible type trait. Apply approach 3.
…templates (#89358) Fixes #85192 Fixes #84492 This patch implements the "IsDeducible" constraint where the template arguments of the alias template can be deduced from the returned type of the synthesized deduction guide, per C++ [over.match.class.deduct]p4. In the implementation, we perform the deduction directly, which is more efficient than the way specified in the standard. Also update relevant CTAD tests which were incorrectly compiled due to the missing constraint.
The following code snippet fails
static_assert
, and the type ofi2
is inferred to be (as reported in the diagnostic message)std::array<std::array<int, 3>, 1>
, which does not even constitute a legalmy_ints
.Godbolt link: https://godbolt.org/z/1Mo9hz4W7 .
The text was updated successfully, but these errors were encountered: