https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123297
Bug ID: 123297
Summary: GCC accepts class template deduction guide with alias
return type instead of simple-template-id
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Keywords: accepts-invalid
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: attackerj1113 at gmail dot com
Target Milestone: ---
Consider the following code:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
template <int A>
struct W {
W(int) {}
};
using E = W<1>;
W(int) -> E;
int main() {
W w(0);
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Clang/MSVC reject it, while GCC/EDG accept it.
https://godbolt.org/z/n3KPeKvez
In my opinion, GCC accepts a class template deduction guide whose return type
after -> is a using alias (e.g. W(int) -> Alias;) rather than a
simple-template-id (e.g. W(int) -> W<1>;).
According to
[temp.deduct.guide]/3(https://eel.is/c++draft/temp.deduct.guide#3), the return
type must be a simple-template-id naming a class template specialization, so
this code should be ill-formed. Clang/MSVC correctly rejects it, leading to a
portability and standard-conformance discrepancy.
Could you clarify whether this is an intentional GCC design choice or a
defect/bug?