Bug 60531 - template function not resolved when comparing functions
Summary: template function not resolved when comparing functions
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.9.0
: P3 normal
Target Milestone: 10.0
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
: 71382 81059 86302 (view as bug list)
Depends on:
Blocks:
 
Reported: 2014-03-14 20:38 UTC by Harald van Dijk
Modified: 2021-08-12 02:15 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2018-04-23 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Harald van Dijk 2014-03-14 20:38:17 UTC
template <typename T> void f();
int main() { f<int> == f<int>; }

is rejected with

test.cc: In function ‘int main()’:
test.cc:2:24: error: invalid operands of types ‘<unresolved overloaded function type>’ and ‘<unresolved overloaded function type>’ to binary ‘operator==’
 int main() { f<int> == f<int>; }

I see no reason why this would be invalid, and it is accepted by all other compilers I was able to test (clang, Intel, Sun, MSVC), but it is rejected by GCC at least as far back as 4.3.
Comment 1 Harald van Dijk 2014-03-15 12:06:38 UTC
It is rejected as far back as 2.95.x, so almost certainly not a regression.
Comment 2 Jonathan Wakely 2018-04-23 09:53:42 UTC
Confirmed. Possibly related to PR 64194 although that involves functions with deduced return types, and this one doesn't.
Comment 3 Harald van Dijk 2019-05-18 08:56:38 UTC
I posted a patch <https://gcc.gnu.org/ml/gcc-patches/2019-04/msg00539.html> over a month ago; I am including the link here in case I end up forgetting to keep pinging.
Comment 4 Marek Polacek 2019-05-18 15:06:05 UTC
(In reply to Harald van Dijk from comment #3)
> I posted a patch <https://gcc.gnu.org/ml/gcc-patches/2019-04/msg00539.html>
> over a month ago; I am including the link here in case I end up forgetting
> to keep pinging.

Sorry about that and thanks for the patch.  It looked fine to me but I'll try to take a closer look at it next week (but won't be able to approve it anyway.)
Comment 5 Jason Merrill 2019-06-04 14:49:09 UTC
Author: jason
Date: Tue Jun  4 14:48:38 2019
New Revision: 271910

URL: https://gcc.gnu.org/viewcvs?rev=271910&root=gcc&view=rev
Log:
PR c++/60531 - Wrong error about unresolved overloaded function

For PR60531, GCC wrongly rejects function templates with explicitly
specified template arguments as overloaded. They are resolved by
resolve_nondeduced_context, which is normally called by
cp_default_conversion through decay_conversion, but the latter have
extra effects making them unusable here. Calling the former directly
does work.

	* typeck.c (cp_build_binary_op): See if overload can be resolved.
	(cp_build_unary_op): Ditto.

	* g++.dg/template/operator15.C: New test.

Added:
    trunk/gcc/testsuite/g++.dg/template/operator15.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/typeck.c
Comment 6 Harald van Dijk 2019-06-06 22:12:15 UTC
Thanks for approving and committing!
Comment 7 Patrick Palka 2021-01-19 16:36:53 UTC
*** Bug 86302 has been marked as a duplicate of this bug. ***
Comment 8 Andrew Pinski 2021-07-28 05:18:54 UTC
*** Bug 71382 has been marked as a duplicate of this bug. ***
Comment 9 Andrew Pinski 2021-08-12 02:15:16 UTC
*** Bug 81059 has been marked as a duplicate of this bug. ***