https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124951
Bug ID: 124951
Summary: "redeclaration of friend 'template<class> a b()' may
not have default template arguments", but is first
non-friend declaration
Product: gcc
Version: 15.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: nabijaczleweli at nabijaczleweli dot xyz
Target Milestone: ---
I reduced a.cpp from real code that failed to build on GCC. b.cpp is what I
expected to work in response to the GCC error, and neither GCC nor Clang accept
it. I think a.cpp should be accepted? Per temp.param#17 I think b.cpp should be
rejected.
$ head ?.cpp
==> a.cpp <==
class ls {
template <class> friend class ls ls();
};
template <class = void> class ls ls() {}
==> b.cpp <==
class ls {
template <class = void> friend class ls ls();
};
template <class> class ls ls() {}
$ clang++ -std=c++20 -c -o a.o a.cpp
$ clang++ -std=c++20 -c -o b.o b.cpp
b.cpp:2:18: error: default template argument not permitted on a friend template
2 | template <class = void> friend class ls ls();
| ^ ~~~~
1 error generated.
$ g++ --std=c++20 -c -o a.o a.cpp
a.cpp:4:34: error: redeclaration of friend 'template<class> ls ls()' may not
have default template arguments
4 | template <class = void> class ls ls() {}
| ^~
a.cpp:2:42: note: 'template<class> ls ls()' previously declared here
2 | template <class> friend class ls ls();
| ^~
$ g++ -std=c++20 -c -o b.o b.cpp
b.cpp:2:52: error: default template arguments may not be used in template
friend declarations
2 | template <class = void> friend class ls ls();
| ^
b.cpp: In function 'ls ls()':
b.cpp:4:33: warning: no return statement in function returning non-void
[-Wreturn-type]
4 | template <class> class ls ls() {}
| ^
g++ (Debian 15.2.0-16) 15.2.0