https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122093
Bug ID: 122093
Summary: Deduction guide using qualified name is rejected with
confusing error
Product: gcc
Version: 15.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: redi at gcc dot gnu.org
Target Milestone: ---
namespace X {
template<class T, class U> struct S { };
template<class T> X::S(T) -> X::S<T, void>;
}
I don't know if this is rejects-valid or just a diagnostic bug:
dg.cc:3:33: error: ‘X::S(T) -> S<T, void>’ should have been declared inside ‘X’
3 | template<class T> X::S(T) -> X::S<T, void>;
| ^~~~~~~~~~
It _was_ declared inside namespace X, so the error is misleading. Either we
should accept the qualified name X::S for the deduction guide, or give a better
error (and better location, since it's the X::S(T) part that's wrong, I think).
EDG and MSVC think this code is OK. Clang gives an error, although it might
just be a parsing error:
dg.cc:3:23: error: cannot use parentheses when declaring variable with deduced
class template specialization type
3 | template<class T> X::S(T) -> S<T, void>;
| ^
dg.cc:3:24: error: no viable constructor or deduction guide for deduction of
template arguments of 'X::S'
3 | template<class T> X::S(T) -> S<T, void>;
| ^
dg.cc:2:35: note: candidate template ignored: couldn't infer template argument
'T'
2 | template<class T, class U> struct S { };
| ^
dg.cc:2:35: note: implicit deduction guide declared as 'template <class T,
class U> S() -> S<T, U>'
dg.cc:2:35: note: candidate function template not viable: requires 1 argument,
but 0 were provided
2 | template<class T, class U> struct S { };
| ^
dg.cc:2:35: note: implicit deduction guide declared as 'template <class T,
class U> S(S<T, U>) -> S<T, U>'
dg.cc:3:26: error: expected ';' after top level declarator
3 | template<class T> X::S(T) -> S<T, void>;
| ^
| ;
3 errors generated.