public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/100443] New: member using declaration of function templates with different return types does not bring base class overload into derived class
@ 2021-05-06 6:53 gonzalo.gadeschi at gmail dot com
2021-05-06 9:48 ` [Bug c++/100443] " redi at gcc dot gnu.org
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: gonzalo.gadeschi at gmail dot com @ 2021-05-06 6:53 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100443
Bug ID: 100443
Summary: member using declaration of function templates with
different return types does not bring base class
overload into derived class
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: gonzalo.gadeschi at gmail dot com
Target Milestone: ---
GCC incorrectly accepts the following example
(https://gcc.godbolt.org/z/YWd98oGY7):
template <class T> struct A {
template <class U> long f(U) const { return 1; }
};
struct B : A<int> {
using A<int>::f;
template <class U> int f(U) const { return 2; }
};
int main() {
return B{}.f(3);
}
Instead, it should error at "B{}.f(3)", since the call is ambiguous.
A member using declaration brings into the derived class all the overloads of
the specified function from the given base class, except for any overloads
where the derived class has a function declaration with the same signature
([namespace.udecl]/p11).
For non-template functions, the return type is not part of the signature
([defns.signature.member]).
For function templates, the return type is part of the signature
([defns.signature.member.templ]).
In this example, A<int>::f and B::f have different return types (long vs int),
and have different signatures. B::f does not hide A<int>::f, and both B::f and
A<int>::f are available for overload resolution.
Because they have the same parameters types, any call is ambiguous.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/100443] member using declaration of function templates with different return types does not bring base class overload into derived class
2021-05-06 6:53 [Bug c++/100443] New: member using declaration of function templates with different return types does not bring base class overload into derived class gonzalo.gadeschi at gmail dot com
@ 2021-05-06 9:48 ` redi at gcc dot gnu.org
2021-05-06 9:59 ` redi at gcc dot gnu.org
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2021-05-06 9:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100443
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to gnzlbg from comment #0)
> A member using declaration brings into the derived class all the overloads
> of the specified function from the given base class, except for any
> overloads where the derived class has a function declaration with the same
> signature ([namespace.udecl]/p11).
Which standard are you referring to?
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/100443] member using declaration of function templates with different return types does not bring base class overload into derived class
2021-05-06 6:53 [Bug c++/100443] New: member using declaration of function templates with different return types does not bring base class overload into derived class gonzalo.gadeschi at gmail dot com
2021-05-06 9:48 ` [Bug c++/100443] " redi at gcc dot gnu.org
@ 2021-05-06 9:59 ` redi at gcc dot gnu.org
2021-05-06 11:30 ` gonzalo.gadeschi at gmail dot com
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2021-05-06 9:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100443
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
C++11 7.3.3 [namespace.udecl] p15:
"When a using-declarator brings declarations from a base class into a derived
class scope, member functions and member function templates in the derived
class override and/or hide member functions and member function templates with
the same name, parameter-type-list (11.3.5), cv-qualification, and
ref-qualifier (if any) in a base class (rather than conflicting)."
C++14 7.3.3 [namespace.udecl] p15:
Same text.
C++17 10.3.3 [namespace.udecl] p15:
Same text minus the word "scope", and addition of "Such hidden or overridden
declarations are excluded from the set of declarations introduced by the
using-declarator."
C++20 9.9 [namespace.udecl] p15:
Same text with the addition of "trailing requires-clause (if any),"
So I don't see where you're finding anything about signatures in p11. The rule
is based on name, parameter-type-list, cv-qualification, and ref-qualifier. It
doesn't depend on return type. It is the same for member functions and member
function templates.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/100443] member using declaration of function templates with different return types does not bring base class overload into derived class
2021-05-06 6:53 [Bug c++/100443] New: member using declaration of function templates with different return types does not bring base class overload into derived class gonzalo.gadeschi at gmail dot com
2021-05-06 9:48 ` [Bug c++/100443] " redi at gcc dot gnu.org
2021-05-06 9:59 ` redi at gcc dot gnu.org
@ 2021-05-06 11:30 ` gonzalo.gadeschi at gmail dot com
2021-05-06 11:39 ` redi at gcc dot gnu.org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: gonzalo.gadeschi at gmail dot com @ 2021-05-06 11:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100443
--- Comment #3 from gnzlbg <gonzalo.gadeschi at gmail dot com> ---
http://eel.is/c++draft/namespace.udecl#11
> The set of declarations named by a using-declarator that inhabits a class C does not include member functions and member function templates of a base class that correspond to (and thus would conflict with) a declaration of a function or function template in C.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/100443] member using declaration of function templates with different return types does not bring base class overload into derived class
2021-05-06 6:53 [Bug c++/100443] New: member using declaration of function templates with different return types does not bring base class overload into derived class gonzalo.gadeschi at gmail dot com
` (2 preceding siblings ...)
2021-05-06 11:30 ` gonzalo.gadeschi at gmail dot com
@ 2021-05-06 11:39 ` redi at gcc dot gnu.org
2021-05-06 12:35 ` gonzalo.gadeschi at gmail dot com
2021-05-06 16:36 ` gonzalo.gadeschi at gmail dot com
5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2021-05-06 11:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100443
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
That wording was only added to the draft in November, I don't think any
compilers implement all the P1787R6 changes yet.
There is still no mention of signatures, which is why I wondered why you're
talking about them. The definition of correspondence is in [basic.scope.scope],
and also doesn't mention signatures (but does distinguish between functions and
function templates).
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/100443] member using declaration of function templates with different return types does not bring base class overload into derived class
2021-05-06 6:53 [Bug c++/100443] New: member using declaration of function templates with different return types does not bring base class overload into derived class gonzalo.gadeschi at gmail dot com
` (3 preceding siblings ...)
2021-05-06 11:39 ` redi at gcc dot gnu.org
@ 2021-05-06 12:35 ` gonzalo.gadeschi at gmail dot com
2021-05-06 16:36 ` gonzalo.gadeschi at gmail dot com
5 siblings, 0 replies; 7+ messages in thread
From: gonzalo.gadeschi at gmail dot com @ 2021-05-06 12:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100443
--- Comment #5 from gnzlbg <gonzalo.gadeschi at gmail dot com> ---
> There is still no mention of signatures, which is why I wondered why you're talking about them.
Re-reading that part, you are correct that it does not mention signatures. I
misunderstood it.
Reading [basic.scope.scope], i'm not sure if `A::f` "corresponds to" `B::f`.
Does it?
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/100443] member using declaration of function templates with different return types does not bring base class overload into derived class
2021-05-06 6:53 [Bug c++/100443] New: member using declaration of function templates with different return types does not bring base class overload into derived class gonzalo.gadeschi at gmail dot com
` (4 preceding siblings ...)
2021-05-06 12:35 ` gonzalo.gadeschi at gmail dot com
@ 2021-05-06 16:36 ` gonzalo.gadeschi at gmail dot com
5 siblings, 0 replies; 7+ messages in thread
From: gonzalo.gadeschi at gmail dot com @ 2021-05-06 16:36 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100443
--- Comment #6 from gnzlbg <gonzalo.gadeschi at gmail dot com> ---
>From [basic.scope.scope]/p3.3.2 http://eel.is/c++draft/basic.scope.scope#3.3.2
I think that A::f and B::f don't correspond because they are function templates
but their return types differ.
Since they don't correspond, I interpret from [namespace.udecl]/p11
http://eel.is/c++draft/namespace.udecl#11 that the using-declaration must bring
A::f into scope, and then the function call is ambiguous in C++ > 20.
In C++20 and earlier this example seems legal.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2021-05-06 16:36 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-06 6:53 [Bug c++/100443] New: member using declaration of function templates with different return types does not bring base class overload into derived class gonzalo.gadeschi at gmail dot com
2021-05-06 9:48 ` [Bug c++/100443] " redi at gcc dot gnu.org
2021-05-06 9:59 ` redi at gcc dot gnu.org
2021-05-06 11:30 ` gonzalo.gadeschi at gmail dot com
2021-05-06 11:39 ` redi at gcc dot gnu.org
2021-05-06 12:35 ` gonzalo.gadeschi at gmail dot com
2021-05-06 16:36 ` gonzalo.gadeschi at gmail dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).