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

[Clang][C++23] < not parsed as the start of a template list in type-only contexts #102502

Open
MitalAshok opened this issue Aug 8, 2024 · 5 comments
Labels
c++23 clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party

Comments

@MitalAshok
Copy link
Contributor

https://eel.is/c++draft/temp.names#3

A < is interpreted as the delimiter of a template-argument-list if it follows a name [...] that is [...] in a type-only context other than a nested-name-specifier.

This wording was added by P1787R6 for C++23

https://godbolt.org/z/GanbhKTh1

template<typename T>
struct X : T::type<void> {};

template<typename T, typename = typename T::type<void>>
int Y = sizeof(typename T::type<void>);

// CWG2806
template<typename T>
concept C = requires {
  typename T::type<void>;
};

// CWG2903
template<typename T>
struct Z : T::type<void>::type {};

Last two are valid after https://cplusplus.github.io/CWG/issues/2806.html and https://cplusplus.github.io/CWG/issues/2903.html

<source>:2:15: error: use 'template' keyword to treat 'type' as a dependent template name
    2 | struct X : T::type<void> {};
      |               ^
      |               template 
<source>:4:45: error: use 'template' keyword to treat 'type' as a dependent template name
    4 | template<typename T, typename = typename T::type<void>>
      |                                             ^
      |                                             template 
<source>:5:28: error: use 'template' keyword to treat 'type' as a dependent template name
    5 | int Y = sizeof(typename T::type<void>);
      |                            ^
      |                            template 
<source>:10:15: error: use 'template' keyword to treat 'type' as a dependent template name
   10 |   typename T::type<void>;
      |               ^
      |               template 
<source>:15:15: error: use 'template' keyword to treat 'type' as a dependent template name
   15 | struct Z : T::type<void>::type {};
      |               ^
      |               template 

This compiles with -fms-extensions.

MSVC only compiles this with /permissive (not /permissive-):

template<typename T, typename = typename T::type<void>>
int Y = sizeof(typename T::type<void>);

GCC compiles it all.

@github-actions github-actions bot added the clang Clang issues not falling into any other category label Aug 8, 2024
@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" c++23 and removed clang Clang issues not falling into any other category labels Aug 8, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Aug 8, 2024

@llvm/issue-subscribers-clang-frontend

Author: Mital Ashok (MitalAshok)

https://eel.is/c++draft/temp.names#3

> A &lt; is interpreted as the delimiter of a template-argument-list if it follows a name [...] that is [...] in a type-only context other than a nested-name-specifier.

This wording was added by P1787R6 for C++23

https://godbolt.org/z/GanbhKTh1

template&lt;typename T&gt;
struct X : T::type&lt;void&gt; {};

template&lt;typename T, typename = typename T::type&lt;void&gt;&gt;
int Y = sizeof(typename T::type&lt;void&gt;);

// CWG2806
template&lt;typename T&gt;
concept C = requires {
  typename T::type&lt;void&gt;;
};

// CWG2903
template&lt;typename T&gt;
struct Z : T::type&lt;void&gt;::type {};

Last two are valid after https://cplusplus.github.io/CWG/issues/2806.html and https://cplusplus.github.io/CWG/issues/2903.html

&lt;source&gt;:2:15: error: use 'template' keyword to treat 'type' as a dependent template name
    2 | struct X : T::type&lt;void&gt; {};
      |               ^
      |               template 
&lt;source&gt;:4:45: error: use 'template' keyword to treat 'type' as a dependent template name
    4 | template&lt;typename T, typename = typename T::type&lt;void&gt;&gt;
      |                                             ^
      |                                             template 
&lt;source&gt;:5:28: error: use 'template' keyword to treat 'type' as a dependent template name
    5 | int Y = sizeof(typename T::type&lt;void&gt;);
      |                            ^
      |                            template 
&lt;source&gt;:10:15: error: use 'template' keyword to treat 'type' as a dependent template name
   10 |   typename T::type&lt;void&gt;;
      |               ^
      |               template 
&lt;source&gt;:15:15: error: use 'template' keyword to treat 'type' as a dependent template name
   15 | struct Z : T::type&lt;void&gt;::type {};
      |               ^
      |               template 

This compiles with -fms-extensions.

MSVC only compiles this with /permissive (not /permissive-):

template&lt;typename T, typename = typename T::type&lt;void&gt;&gt;
int Y = sizeof(typename T::type&lt;void&gt;);

GCC compiles it all.

@frederick-vs-ja
Copy link
Contributor

frederick-vs-ja commented Aug 9, 2024

https://eel.is/c++draft/temp.names#3

A < is interpreted as the delimiter of a template-argument-list if it follows a name [...] that is [...] in a type-only context other than a nested-name-specifier.

This wording was added by P1787R6 for C++23

These parts of changes seem to be the resolution of CWG1478 but touch more things than the original issue.

Edit: Is this already tracked in #54150?

@MitalAshok
Copy link
Contributor Author

@frederick-vs-ja I don't think this is related to CWG1478 because that's specifically about when there isn't a <.

Reading P1787P6§Parsing makes it seem like type-only contexts (previously: type-id-only contexts, in Clang as ImplicitTypenameContext) were extended to include "implicit template" that doesn't seem to be mentioned in #54150.

@MitalAshok
Copy link
Contributor Author

This might be a dup of #95447

@shafik
Copy link
Collaborator

shafik commented Aug 19, 2024

Also see: #81731

@shafik shafik added the confirmed Verified by a second party label Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++23 clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party
Projects
None yet
Development

No branches or pull requests

5 participants