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

Aliases and uniqueness of lambda in default argument of a class template parameter #123414

Open
cor3ntin opened this issue Jan 17, 2025 · 2 comments
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" diverges-from:edg Does the clang frontend diverge from edg compiler diverges-from:gcc Does the clang frontend diverge from gcc on this issue diverges-from:msvc Does the clang frontend diverge from msvc on this issue

Comments

@cor3ntin
Copy link
Contributor

cor3ntin commented Jan 17, 2025

Consider

template<typename T, typename F = decltype([](){} )>
struct Type {};

template<typename A>
using C = Type<A>;

static_assert(std::same_as<Type<int>,Type<int>>); // #1
static_assert(std::same_as<C<int>,C<int>>); // #2

https://godbolt.org/z/6ofdP1bPz

All compilers reject #1. Only clang rejects #2.

This seems vaguely related, but distinct from CWG2794

Given https://eel.is/c++draft/temp.alias#2

When a template-id refers to the specialization of an alias template, it is equivalent to the associated type obtained by substitution of its template-arguments for the template-parameters in the defining-type-id of the alias template.

And https://eel.is/c++draft/temp#arg.general-9.sentence-1

When a simple-template-id does not name a function, a default template-argument is implicitly instantiated when the value of that default argument is needed.

It's clear as mud (to me) what the expected behavior should be.
CWG discussion https://lists.isocpp.org/core/2025/01/16895.php

@cor3ntin cor3ntin added clang:frontend Language frontend issues, e.g. anything involving "Sema" diverges-from:edg Does the clang frontend diverge from edg compiler diverges-from:gcc Does the clang frontend diverge from gcc on this issue diverges-from:msvc Does the clang frontend diverge from msvc on this issue labels Jan 17, 2025
@llvmbot
Copy link
Member

llvmbot commented Jan 17, 2025

@llvm/issue-subscribers-clang-frontend

Author: cor3ntin (cor3ntin)

Consider
template&lt;typename T, typename F = decltype([](){} )&gt;
struct Type {};

template&lt;typename A&gt;
using C = Type&lt;A&gt;;

static_assert(std::same_as&lt;Type&lt;int&gt;,Type&lt;int&gt;&gt;); // #<!-- -->1
static_assert(std::same_as&lt;C&lt;int&gt;,C&lt;int&gt;&gt;); // #<!-- -->2

https://godbolt.org/z/6ofdP1bPz

All compilers reject #1. Only clang reject #2.
This seems vaguely related, but distinct from
https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#2794

Given https://eel.is/c++draft/temp.alias#2
> When a template-id refers to the specialization of an alias template, it is equivalent to the associated type obtained by substitution of its template-arguments for the template-parameters in the defining-type-id of the alias template.

And https://eel.is/c++draft/temp#arg.general-9.sentence-1
> When a simple-template-id does not name a function, a default template-argument is implicitly instantiated when the value of that default argument is needed.

It's clear as mud (to me) what the expected behavior should be. I'll contact CWG

@cor3ntin
Copy link
Contributor Author

@t3nsor @zygoloid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" diverges-from:edg Does the clang frontend diverge from edg compiler diverges-from:gcc Does the clang frontend diverge from gcc on this issue diverges-from:msvc Does the clang frontend diverge from msvc on this issue
Projects
None yet
Development

No branches or pull requests

2 participants