Skip to content
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

[temp.deduct.type] p6 type name includes non-deduced context #4878

Open
xmh0511 opened this issue Sep 8, 2021 · 5 comments
Open

[temp.deduct.type] p6 type name includes non-deduced context #4878

xmh0511 opened this issue Sep 8, 2021 · 5 comments

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented Sep 8, 2021

[temp.deduct.type] p6 says

When a type name is specified in a way that includes a non-deduced context, all of the types that comprise that type name are also non-deduced. However, a compound type can include both deduced and non-deduced types.

Consider this example

template<class  U ,class T>
struct A{
    A(T){}
};
template<class U>
struct unknow_content{
    using type = U;
};

template<class U, class T>
void fun(A<U, typename unknow_content<T>::type>, T,U){}

int main(){
   fun(0,0,0);  // ill-formed
}

the type name A<U, typename unknow_content<T>::type> includes a non-deduced context typename unknow_content<T>::type, hence the U that comprises the type name A<U, typename unknow_content<T>::type> is also non-deduced?

@jwakely
Copy link
Member

jwakely commented Sep 8, 2021

It can't be deduced from the first argument, but it can still be deduced from the third argument.

@jensmaurer
Copy link
Member

Yes, the U in the first parameter is a non-deduced context, but it's deduced from the third parameter.

@xmh0511
Copy link
Contributor Author

xmh0511 commented Sep 8, 2021

@jensmaurer @jwakely However, the implementations say U cannot be deduced. See https://godbolt.org/z/Wdso85Pxr

mismatched types 'A<U, typename unknow_content::type>' and 'int'

@jensmaurer jensmaurer reopened this Sep 8, 2021
@jensmaurer
Copy link
Member

It seems "When a type name is specified in a way that includes a non-deduced context...", the "includes" is hazy here. Maybe "nearest enclosing type name" is what compilers implement.

@xmh0511
Copy link
Contributor Author

xmh0511 commented Sep 8, 2021

The intent seems

When a type whose nested-name-specifier is a non-deduced context, all of the types that comprise that type are also non-deduced. However, a compound type can include both deduced and non-deduced types.

The formal example indicates that.

[Example 2: If a type is specified as A​::​B, both T and T2 are non-deduced. Likewise, if a type is specified as A<I+J>​::​X, I, J, and T are non-deduced. If a type is specified as void f(typename A< T >​::​B, A< T >), the T in A< T >​::​B is non-deduced but the T in A is deduced. — end example]

Furthermore, decltype(T{})::B<T2>.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants