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

Class template argument deduction with using fails, apparently incorrectly #73093

Closed
geometrian opened this issue Nov 22, 2023 · 8 comments
Closed
Assignees
Labels
c++20 clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party rejects-valid

Comments

@geometrian
Copy link

Consider the following simple C++20 example:

template< class Tval, class Targ >
struct Foo {
	Foo( Targ arg ) {}
};

template< class Targ >
using FooF = Foo< float, Targ >;

void test() {
	FooF foo( 6 );
}

GCC and MSVC compile it happily. However, Clang (tested 18.0.0 d328512) claims the using doesn't amount to a class template:

<source>:10:7: error: alias template 'FooF' requires template arguments; argument deduction only allowed for class templates
   10 |         FooF foo( 6 );
      |              ^

This is a bit strange—it's true the using is not a class template per-se, but it is an alias for one. Indeed, my reading of the documentation (emphasis mine):

When a function-style cast or declaration of a variable uses the name of an alias template A without an argument list as the type specifier, where A is defined as an alias of B, the scope of B is non-dependent, and B is either a class template or a similarly-defined alias template, deduction will proceed in the same way as for class templates

—suggests that it should work, but I am not enough of a language lawyer to say for sure.

@llvmbot
Copy link
Collaborator

llvmbot commented Nov 22, 2023

@llvm/issue-subscribers-c-17

Author: Ian Mallett (geometrian)

Consider the following simple C++20 example: ```cpp template< class Tval, class Targ > struct Foo { Foo( Targ arg ) {} };

template< class Targ >
using FooF = Foo< float, Targ >;

void test() {
FooF foo( 6 );
}

GCC and MSVC compile it happily. However, Clang (tested 18.0.0 d3285123bc9c2e170c8aa7e418c132119bc7aaf1) claims the `using` doesn't amount to a class template:
```text
&lt;source&gt;:10:7: error: alias template 'FooF' requires template arguments; argument deduction only allowed for class templates
   10 |         FooF foo( 6 );
      |              ^

This is a bit strange—it's true the using is not a class template per-se, but it is an alias for one. Indeed, my reading of the documentation (emphasis mine):
> When a function-style cast or declaration of a variable uses the name of an alias template A without an argument list as the type specifier, where A is defined as an alias of B<ArgList>, the scope of B is non-dependent, and B is either a class template or a similarly-defined alias template, deduction will proceed in the same way as for class templates

—suggests that it should work, but I am not enough of a language lawyer to say for sure.

@EugeneZelenko EugeneZelenko added the clang:frontend Language frontend issues, e.g. anything involving "Sema" label Nov 22, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Nov 22, 2023

@llvm/issue-subscribers-clang-frontend

Author: Ian Mallett (geometrian)

Consider the following simple C++20 example: ```cpp template< class Tval, class Targ > struct Foo { Foo( Targ arg ) {} };

template< class Targ >
using FooF = Foo< float, Targ >;

void test() {
FooF foo( 6 );
}

GCC and MSVC compile it happily. However, Clang (tested 18.0.0 d3285123bc9c2e170c8aa7e418c132119bc7aaf1) claims the `using` doesn't amount to a class template:
```text
&lt;source&gt;:10:7: error: alias template 'FooF' requires template arguments; argument deduction only allowed for class templates
   10 |         FooF foo( 6 );
      |              ^

This is a bit strange—it's true the using is not a class template per-se, but it is an alias for one. Indeed, my reading of the documentation (emphasis mine):
> When a function-style cast or declaration of a variable uses the name of an alias template A without an argument list as the type specifier, where A is defined as an alias of B<ArgList>, the scope of B is non-dependent, and B is either a class template or a similarly-defined alias template, deduction will proceed in the same way as for class templates

—suggests that it should work, but I am not enough of a language lawyer to say for sure.

@Backl1ght
Copy link
Member

I think this is p1814r0, which is not yet implemented in clang.

@shafik
Copy link
Collaborator

shafik commented Nov 27, 2023

Confirmed: https://godbolt.org/z/74db3E5Tq

@shafik shafik added confirmed Verified by a second party c++20 and removed c++17 labels Nov 27, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Nov 27, 2023

@llvm/issue-subscribers-c-20

Author: Ian Mallett (geometrian)

Consider the following simple C++20 example: ```cpp template< class Tval, class Targ > struct Foo { Foo( Targ arg ) {} };

template< class Targ >
using FooF = Foo< float, Targ >;

void test() {
FooF foo( 6 );
}

GCC and MSVC compile it happily. However, Clang (tested 18.0.0 d3285123bc9c2e170c8aa7e418c132119bc7aaf1) claims the `using` doesn't amount to a class template:
```text
&lt;source&gt;:10:7: error: alias template 'FooF' requires template arguments; argument deduction only allowed for class templates
   10 |         FooF foo( 6 );
      |              ^

This is a bit strange—it's true the using is not a class template per-se, but it is an alias for one. Indeed, my reading of the documentation (emphasis mine):
> When a function-style cast or declaration of a variable uses the name of an alias template A without an argument list as the type specifier, where A is defined as an alias of B<ArgList>, the scope of B is non-dependent, and B is either a class template or a similarly-defined alias template, deduction will proceed in the same way as for class templates

—suggests that it should work, but I am not enough of a language lawyer to say for sure.

@Backl1ght Backl1ght self-assigned this Nov 28, 2023
@hokein
Copy link
Collaborator

hokein commented Dec 7, 2023

This is a missing feature in clang which is already tracking in #54051. I'm closing it as this is a duplication.

@hokein hokein closed this as completed Dec 7, 2023
@hokein
Copy link
Collaborator

hokein commented Dec 7, 2023

@Backl1ght, I see you self-assigned to this issue, are you working on it? (I also have a plan to look at it).

@Backl1ght
Copy link
Member

@hokein I'd like to work on it, but I have little time recently. I think it would be better if you can pick it up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++20 clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party rejects-valid
Projects
Status: Done
Development

No branches or pull requests

7 participants