https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119859
Bug ID: 119859
Summary: [15 Regression?] template member function overload
with base class
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: Laurent.Rineau__gcc at normalesup dot org
Target Milestone: ---
Created attachment 61153
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=61153&action=edit
source code
The attached source code compiled with g++-14.2.0 but not with g++-15. See also
on Godbolt: https://godbolt.org/z/W1f9xYE6s
The error message is an ambiguity:
<source>: In function 'int main()':
<source>:12:11: error: call of overloaded 'f()' is ambiguous
12 | b.f<int>();
| ~~~~~~~~^~
<source>:12:11: note: there are 2 candidates
<source>:2:33: note: candidate 1: 'const A& A::f() const [with T = int]'
2 | template<typename T> const A& f() const { return *this; }
| ^
<source>:7:33: note: candidate 2: 'const B& B::f() const [with T = int]'
7 | template<typename T> const B& f() const { return *this; }
| ^
Compiler returned: 1
Actually, I am not completely sure that is a regression. According to
https://eel.is/c++draft/namespace.udecl#12:
> For the purpose of forming a set of candidates during overload resolution,
> the functions named by a using-declaration in a derived class are treated as
> though they were direct members of the derived class.
In particular, the implicit object parameter is treated as if it were a
reference to the derived class rather than to the base class
([over.match.funcs]).
So the function templates only differ by their return types.