Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CWG2945 [basic.link] "Two declarations of an entity" vs corresponding overloads #630

Open
Endilll opened this issue Oct 27, 2024 · 3 comments

Comments

@Endilll
Copy link

Endilll commented Oct 27, 2024

Full name of submitter: Vlad Serebrennikov
Reference (section label): [basic.link]

[basic.link]/11 reads:

For any two declarations of an entity E:
— <...>
— If one declares E to be a function template or a (partial specialization of a) variable template, the other shall declare E to be one with an equivalent template-head and type.

Those two bullets don't seem to take into account that in order for [basic.link]/11 to apply, declaration matching ([basic.link]/8) has to establish that two declaration indeed declare the same entity, which involves establishing whether those two declarations correspond ([basic.scope.scope]/4), which relies on the definition of corresponding overloads. The latter puts much more precise and strict requirements on function template declarations ([basic.scope.scope]/4):

Two function or function template declarations declare corresponding overloads if
— both declare functions <...>, or
— both declare function templates with corresponding signatures and equivalent template-heads and trailing requires-clauses (if any).

So I think there's no way to arrive at [basic.link]/11.6 with two declarations of function templates that declare the same entity but don't have equivalent template-heads. I think [basic.link]/11 should either stop caring about that, or sync with corresponding overloads on exact details like trailing requires-clause.

We might want to apply a similar change to [basic.link]/11.1, but in this case [basic.link]/11.1 is stricter than corresponding overloads, because the latter doesn't consider return types (maybe it should?).

Also, while we're looking at [basic.link]/11.6: is it correct to talk about type of a function template and variable template?

Suggested resolution:

For any two declarations of an entity E:
— <...>
— If one declared E to be a function template, the other shall do so.
[Note: Two declarations of the same function template are required to have equivalent template-heads ([basic.scope.scope]). — end note]
— If one declares E to be a function template or a (partial specialization of a) variable template, the other shall declare E to be one with an equivalent template-head and type.

@Endilll
Copy link
Author

Endilll commented Oct 27, 2024

Also, while we're looking at [basic.link]/11.6: is it correct to talk about type of a function template and variable template?

I forgot to mention that this was discussed a bit on Mattermost: https://chat.isocpp.org/general/pl/zxonhyg8wi86bpys41tpsxpjja

@jensmaurer
Copy link
Member

This change drops the "same type" requirement. Two declarations can differ in "noexcept", but otherwise correspond, but that ought to be ill-formed:

template<class T> void f(T);
template<class T> void f(T) noexcept;

@jensmaurer
Copy link
Member

CWG2945

@jensmaurer jensmaurer changed the title [basic.link] "Two declarations of an entity" vs corresponding overloads CWG2945 [basic.link] "Two declarations of an entity" vs corresponding overloads Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants