Bug 87429 - Strange overload resolution with decltype in template function
Summary: Strange overload resolution with decltype in template function
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
Depends on:
Blocks: decltype
  Show dependency treegraph
 
Reported: 2018-09-25 08:46 UTC by Alexander Zaitsev
Modified: 2022-02-01 15:41 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work: 11.1.0
Known to fail: 10.3.0
Last reconfirmed: 2022-02-01 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Zaitsev 2018-09-25 08:46:13 UTC
gcc(trunk) for this code:

#include <iostream>

template <typename T> int foo(int) { return 1; }
template <typename T> int foo(decltype(T{})) { return 2; }
template <typename T> int foo(decltype(int(T{}))) { return 3;}

int main()
{
    std::cout << foo<int>(0);
}

prints '2'. But as I understand here should be compilation error because of ambiguous call to overload function
Comment 1 Jonathan Wakely 2018-09-25 10:29:34 UTC
Clang also compiles it, and prints "1".

EDG rejects it as ambiguous:

"a.cc", line 8: error: more than one instance of overloaded function "foo"
          matches the argument list:
            function template "int foo<T>(int)"
            function template "int foo<T>(int)"
            argument types are: (int)
      return foo<int>(0);
             ^

1 error detected in the compilation of "a.cc".
Comment 2 Andrew Pinski 2021-12-11 05:29:31 UTC
Seems fixed in GCC 11+.
Comment 3 Martin Liška 2022-02-01 15:41:36 UTC
Fixed with r11-123-ge42f342652981aa9.