public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/96976] New: g++ reports "call of overloaded '...' is ambiguous" when universal reference is used
@ 2020-09-08 11:44 igor.chorazewicz at intel dot com
  2020-09-08 11:56 ` [Bug c++/96976] " redi at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: igor.chorazewicz at intel dot com @ 2020-09-08 11:44 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96976

            Bug ID: 96976
           Summary: g++ reports "call of overloaded '...' is ambiguous"
                    when universal reference is used
           Product: gcc
           Version: 9.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: igor.chorazewicz at intel dot com
  Target Milestone: ---

Following code compiles fine on clang++ and gcc 11 but fails on all older gcc
versions I tested (9.3.0, 9.2.1, 10.0.1).

#include <type_traits>

template <typename... Args>
void f(int &&a, Args&&... args)
{
}

template <typename K, typename... Args, typename = typename
std::enable_if<true, K>::type>
void f(K&& k, Args&&... args)
{
}

int main() {
    f(1, 2);
    return 0;
}

The error is:
prog.cc: In function 'int main()':
prog.cc:14:11: error: call of overloaded 'f(int, int)' is ambiguous
   14 |     f(1, 2);
      |           ^
prog.cc:4:6: note: candidate: 'void f(int&&, Args&& ...) [with Args = {int}]'
    4 | void f(int &&a, Args&&... args)
      |      ^
prog.cc:9:6: note: candidate: 'void f(K&&, Args&& ...) [with K = int; Args =
{int}; <template-parameter-1-3> = int]'
    9 | void f(K&& k, Args&&... args)


Note that if I remove the dummy enable_if, the program compiles fine. It also
compiles if there is no template parameter pack (Args...)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/96976] g++ reports "call of overloaded '...' is ambiguous" when universal reference is used
  2020-09-08 11:44 [Bug c++/96976] New: g++ reports "call of overloaded '...' is ambiguous" when universal reference is used igor.chorazewicz at intel dot com
@ 2020-09-08 11:56 ` redi at gcc dot gnu.org
  2020-09-08 12:17 ` igor.chorazewicz at intel dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2020-09-08 11:56 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96976

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed on trunk by r11-1571

It's also fixed on the gcc-10 branch by r10-8343

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/96976] g++ reports "call of overloaded '...' is ambiguous" when universal reference is used
  2020-09-08 11:44 [Bug c++/96976] New: g++ reports "call of overloaded '...' is ambiguous" when universal reference is used igor.chorazewicz at intel dot com
  2020-09-08 11:56 ` [Bug c++/96976] " redi at gcc dot gnu.org
@ 2020-09-08 12:17 ` igor.chorazewicz at intel dot com
  2020-09-09 13:32 ` vorfeed.canal at gmail dot com
  2020-09-11 13:27 ` mpolacek at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: igor.chorazewicz at intel dot com @ 2020-09-08 12:17 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96976

--- Comment #2 from Igor Chorazewicz <igor.chorazewicz at intel dot com> ---
(In reply to Jonathan Wakely from comment #1)
> Fixed on trunk by r11-1571
> 
> It's also fixed on the gcc-10 branch by r10-8343

Do you plan to backport it to older gcc versions?

Also, do you by any chance, have any ideas how to workaround it for now?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/96976] g++ reports "call of overloaded '...' is ambiguous" when universal reference is used
  2020-09-08 11:44 [Bug c++/96976] New: g++ reports "call of overloaded '...' is ambiguous" when universal reference is used igor.chorazewicz at intel dot com
  2020-09-08 11:56 ` [Bug c++/96976] " redi at gcc dot gnu.org
  2020-09-08 12:17 ` igor.chorazewicz at intel dot com
@ 2020-09-09 13:32 ` vorfeed.canal at gmail dot com
  2020-09-11 13:27 ` mpolacek at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: vorfeed.canal at gmail dot com @ 2020-09-09 13:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96976

Vorfeed Canal <vorfeed.canal at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |vorfeed.canal at gmail dot com

--- Comment #3 from Vorfeed Canal <vorfeed.canal at gmail dot com> ---
Why couldn't you use std::enable_if in it's usual (for functions) place?

Like this:

template <typename K, typename... Args>
auto f(K&& k, Args&&... args) -> std::enable_if_t<true, void>
{
}

Works with all somewhat decent compilers:

https://godbolt.org/z/rds3vM

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/96976] g++ reports "call of overloaded '...' is ambiguous" when universal reference is used
  2020-09-08 11:44 [Bug c++/96976] New: g++ reports "call of overloaded '...' is ambiguous" when universal reference is used igor.chorazewicz at intel dot com
                   ` (2 preceding siblings ...)
  2020-09-09 13:32 ` vorfeed.canal at gmail dot com
@ 2020-09-11 13:27 ` mpolacek at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-09-11 13:27 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96976

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |mpolacek at gcc dot gnu.org

--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Yeah, I don't expect this to be backported to 9, sorry.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-09-11 13:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-08 11:44 [Bug c++/96976] New: g++ reports "call of overloaded '...' is ambiguous" when universal reference is used igor.chorazewicz at intel dot com
2020-09-08 11:56 ` [Bug c++/96976] " redi at gcc dot gnu.org
2020-09-08 12:17 ` igor.chorazewicz at intel dot com
2020-09-09 13:32 ` vorfeed.canal at gmail dot com
2020-09-11 13:27 ` mpolacek at gcc dot gnu.org

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).