This fixes a regression introduced by bee78b88f.
When we form a deduction guide for a constructor, basically, we do the
following work:
- Collect template parameters from the constructor's surrounding class
template, if present.
- Collect template parameters from the constructor.
- Splice these template parameters together into a new template
parameter list.
- Turn all the references (e.g. the function parameter list) to the
invented parameter list by applying a `TreeTransform` to the function
type.
In the previous fix, we handled cases of nested class templates by
substituting the "outer" template parameters (i.e. those not declared at
the surrounding class template or the constructor) with the
instantiating template arguments. The approach per se makes sense, but
there was a flaw in the following case:
```cpp
template <typename U, typename... Us> struct X {
template <typename V> struct Y {
template <typename T> Y(T) {}
};
template <typename T> Y(T) -> Y<T>;
};
X<int>::Y y(42);
```
While we're transforming the parameters for `Y(T)`, we first attempt to
transform all references to `V` and `T`; then, we handle the references
to outer parameters `U` and `Us` using the template arguments from
`X<int>` by transforming the same `ParamDecl`. However, the first step
results in the reference `T` being `<template-param-0-1>` because the
invented `T` is the last of the parameter list of the deduction guide,
and what we're substituting with is a corresponding parameter pack
(which is `Us`, though empty). Hence we're messing up the substitution.
I think we can resolve it by reversing the substitution order, which
means handling outer template parameters first and then the inner
parameters.
There's no release note because this is a regression in 18, and I hope
we can catch up with the last release.
Fixes https://github.com/llvm/llvm-project/issues/88142
101 lines
2.6 KiB
C++
101 lines
2.6 KiB
C++
// RUN: %clang_cc1 -std=c++20 -verify %s
|
|
|
|
template<class T> struct S {
|
|
template<class U> struct N {
|
|
N(T) {}
|
|
N(T, U) {}
|
|
template<class V> N(V, U) {}
|
|
};
|
|
};
|
|
|
|
S<int>::N x{"a", 1};
|
|
using T = decltype(x);
|
|
using T = S<int>::N<int>;
|
|
|
|
template<class X> struct default_ftd_argument {
|
|
template<class Y> struct B {
|
|
template<class W = X, class Z = Y, class V = Z, int I = 0> B(Y);
|
|
};
|
|
};
|
|
|
|
default_ftd_argument<int>::B default_arg("a");
|
|
using DefaultArg = decltype(default_arg);
|
|
using DefaultArg = default_ftd_argument<int>::B<const char *>;
|
|
|
|
template<bool> struct test;
|
|
template<class X> struct non_type_param {
|
|
template<class Y> struct B {
|
|
B(Y);
|
|
template<class Z, test<Z::value> = 0> B(Z);
|
|
};
|
|
};
|
|
|
|
non_type_param<int>::B ntp = 5;
|
|
using NonTypeParam = decltype(ntp);
|
|
using NonTypeParam = non_type_param<int>::B<int>;
|
|
|
|
template<typename A, typename T>
|
|
concept True = true;
|
|
|
|
template<typename T>
|
|
concept False = false;
|
|
|
|
template<class X> struct concepts {
|
|
template<class Y> struct B {
|
|
template<class K = X, True<K> Z> B(Y, Z);
|
|
};
|
|
};
|
|
|
|
concepts<int>::B cc(1, 3);
|
|
using Concepts = decltype(cc);
|
|
using Concepts = concepts<int>::B<int>;
|
|
|
|
template<class X> struct requires_clause {
|
|
template<class Y> struct B {
|
|
template<class Z> requires true
|
|
B(Y, Z);
|
|
};
|
|
};
|
|
|
|
requires_clause<int>::B req(1, 2);
|
|
using RC = decltype(req);
|
|
using RC = requires_clause<int>::B<int>;
|
|
|
|
template<typename X> struct nested_init_list {
|
|
template<True<X> Y>
|
|
struct B {
|
|
X x;
|
|
Y y;
|
|
};
|
|
|
|
template<False F>
|
|
struct concept_fail { // #INIT_LIST_INNER_INVALID
|
|
X x;
|
|
F f;
|
|
};
|
|
};
|
|
|
|
nested_init_list<int>::B nil {1, 2};
|
|
using NIL = decltype(nil);
|
|
using NIL = nested_init_list<int>::B<int>;
|
|
|
|
// expected-error@+1 {{no viable constructor or deduction guide for deduction of template arguments of 'concept_fail'}}
|
|
nested_init_list<int>::concept_fail nil_invalid{1, ""};
|
|
// expected-note@#INIT_LIST_INNER_INVALID {{candidate template ignored: substitution failure [with F = const char *]: constraints not satisfied for class template 'concept_fail' [with F = const char *]}}
|
|
// expected-note@#INIT_LIST_INNER_INVALID {{candidate function template not viable: requires 1 argument, but 2 were provided}}
|
|
// expected-note@#INIT_LIST_INNER_INVALID {{candidate function template not viable: requires 0 arguments, but 2 were provided}}
|
|
|
|
namespace GH88142 {
|
|
|
|
template <typename, typename...> struct X {
|
|
template <typename> struct Y {
|
|
template <typename T> Y(T) {}
|
|
};
|
|
|
|
template <typename T> Y(T) -> Y<T>;
|
|
};
|
|
|
|
X<int>::Y y(42);
|
|
|
|
} // namespace PR88142
|