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

[c++11] clang allows questionable CTAD for template base of derived class with default argument #97532

Open
Rush10233 opened this issue Jul 3, 2024 · 2 comments
Labels
accepts-invalid clang:frontend Language frontend issues, e.g. anything involving "Sema"

Comments

@Rush10233
Copy link

The following code is accepted by clang but rejected by GCC,MSVC and ICC with the option of -std=c++11:

template<typename,typename=int> struct Base { };

struct Derived : Base<void> { };

template<template<typename> class TT>
void func (TT<void>) { }

int main () {
  func (Derived { });
}

https://timsong-cpp.github.io/cppwp/std11/temp.deduct.call#4 says that "If P is a class and P has the form simple-template-id, then the transformed A can be a derived class of the deduced A." So the class Derived passed in line 9 can be deduced to its base type.

But the parameter requested by func is a template class with 1 argument, while class Base has 2(including 1 with default value), which seems incompatible.

It's interesting that gcc accepts that code under -std=c++20, but other compilers don't. It seems that more standard docs need to be consulted.

https://godbolt.org/z/G7fenEsYY

@github-actions github-actions bot added the clang Clang issues not falling into any other category label Jul 3, 2024
@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" accepts-invalid and removed clang Clang issues not falling into any other category labels Jul 3, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 3, 2024

@llvm/issue-subscribers-clang-frontend

Author: None (Rush10233)

The following code is accepted by clang but rejected by GCC,MSVC and ICC with the option of `-std=c++11`:
template&lt;typename,typename=int&gt; struct Base { };

struct Derived : Base&lt;void&gt; { };

template&lt;template&lt;typename&gt; class TT&gt;
void func (TT&lt;void&gt;) { }

int main () {
  func (Derived { });
}

[https://timsong-cpp.github.io/cppwp/std11/temp.deduct.call#4](https://timsong-cpp.github.io/cppwp/std11/temp.deduct.call#4) says that "If P is a class and P has the form simple-template-id, then the transformed A can be a derived class of the deduced A." So the class Derived passed in line 9 can be deduced to its base type.

But the parameter requested by func is a template class with 1 argument, while class Base has 2(including 1 with default value), which seems incompatible.

It's interesting that gcc accepts that code under -std=c++20, but other compilers don't. It seems that more standard docs need to be consulted.

https://godbolt.org/z/G7fenEsYY

@MitalAshok
Copy link
Contributor

I think this is CWG150/P0522R0, which was controlled by -frelaxed-template-template-args, which became on by default in #89807

@mizvekov Should this be accepted in C++11/14:

template<typename,typename=int> struct Base { };

template<template<typename> class TT>
void func (TT<void>) { }

int main () {
  func (Base<void> { });
}

? It appears the core issue only made changes to C++17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepts-invalid clang:frontend Language frontend issues, e.g. anything involving "Sema"
Projects
None yet
Development

No branches or pull requests

4 participants