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

CWG2873 [over.over] Is it intended that when a function is overloaded with a function template then its address cannot be taken unambiguously #516

Open
ranaanoop opened this issue Mar 16, 2024 · 4 comments

Comments

@ranaanoop
Copy link

Full name of submitter: Anoop Rana

Reference (section label): [over.over]

Link to reflector thread (if any): https://stackoverflow.com/questions/78170991/in-c-why-cant-i-take-the-address-of-a-function-that-also-has-a-templated-vers

Issue description:

I came across the following code that is rejected by all three compilers and seems to be ill-formed as per current wording in over.over#3.

template <typename T>
void AcceptAnything(T&&);

void Foo();

template <typename T>
void Foo();

void Bar() {
  AcceptAnything(&Foo);
}

I think this is ill-formed because(as explained here) because the specialization from the function template cannot be formed here so nothing can be added to the set and so it is ill-formed(I may be wrong here but as far as I understand the topic this is what makes it ill-formed). But I don't think the whole program should be ill-formed here as there is another non-template function available that can be used. Instead this inability to form a specialization from the function template can be ignored as a non-template function that can be used is available.

Suggested resolution:

Maybe something like the following can be added:

The program is ill-formed if this is part of the final result of overload resolution.

@jensmaurer
Copy link
Member

Hm... That's odd. We do say "if any"; the inability to produce a template specialization shouldn't cause a hard error for the entire set, I think.

@ranaanoop
Copy link
Author

@jensmaurer Yes, at first I also though that the "if any" should make the program well-formed. But all compilers rejecting the program seems to suggest that it should be made more clear perhaps. Though it is possible that as per current wording("if any") all compilers are wrong but I wanted to confirm what is intended here. I will update the answer afterwards.

@ranaanoop
Copy link
Author

ranaanoop commented Mar 16, 2024

@jensmaurer over.over#5.sentence-2 seems to make this well-formed. Although there will be no specialization that can be generated from the function template here so nothing will be eliminated from the set. So the one candidate is the non-template function which should be used. Even if somehow a specialization could've been generated, the non-template function should've been used as per over.over#5.

@jensmaurer
Copy link
Member

CWG2873

@jensmaurer jensmaurer changed the title [over.over] Is it intended that when a function is overloaded with a function template then its address cannot be taken unambiguously CWG2873 [over.over] Is it intended that when a function is overloaded with a function template then its address cannot be taken unambiguously Mar 17, 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