public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/65599] New: [c++14] Failing overload resolution when combining return type deduction and explicit R/L-value methods
@ 2015-03-27 10:55 anders at sjogren dot info
  2015-03-27 11:36 ` [Bug c++/65599] " redi at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: anders at sjogren dot info @ 2015-03-27 10:55 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 65599
           Summary: [c++14] Failing overload resolution when combining
                    return type deduction and explicit R/L-value methods
           Product: gcc
           Version: 4.9.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: anders at sjogren dot info

The following code uses return type deduction (auto) and different methods for
L-value and R-value objects. It seems when combining the two, gcc 4.9.2 has
problems with overload resolution: "call of overloaded 'f()' is ambiguous".

Is this a bug or just another strange C++ corner case? Clang accepts it as
expected.

struct T {
  auto f() & {
    return int{0};
  }
  auto f() && {
    return string{""};
  }
};

void test_it() {
  //Calling with L-value object. Fails with "call of overloaded 'f()' is
ambiguous").
  T t;
  int s = t.f();

  //Calling with R-value object. Fails with "call of overloaded 'f()' is
ambiguous").
  string i = T{}.f();
}

struct T2 {
  auto f() & -> int {
    return 0;
  }
  auto f() && -> string {
    return "";
  }
};

void test_it_2() {
  //Calling with L-value object. Works just fine when the return type is
stated!
  T2 t;
  int s = t.f();

  //Calling with R-value object. Works just fine when the return type is
stated!
  string i = T2{}.f();
}

struct T3 {
  auto f() & {
    return 0;
  }
  auto f() && -> string {
    return "";
  }
};

void test_it_3() {
  //Calling with L-value object. Works fine when the non-selected overload has
a non-deduced return type(!).
  T3 t;
  int s = t.f();

  //Calling with R-value object. Doesn't work even though the selected overload
has a non-deduced return type.
  string i = T3{}.f();
}

The example can be studied using online compilers here:
gcc 4.9.2: http://goo.gl/itZliQ
clang 3.5.1: http://goo.gl/yffVa8

The topic on if its a bug or a c++ quirk was posted on
http://stackoverflow.com/questions/29298029/c-gcc-bug-when-combining-auto-and-r-value-in-methods
, but I also posted it here after that I felt fairly sure it was a bug.

A possibly related bug is:
Bug 64194 - [C++14] <unresolved overloaded function type> for function template
with auto return


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

* [Bug c++/65599] [c++14] Failing overload resolution when combining return type deduction and explicit R/L-value methods
  2015-03-27 10:55 [Bug c++/65599] New: [c++14] Failing overload resolution when combining return type deduction and explicit R/L-value methods anders at sjogren dot info
@ 2015-03-27 11:36 ` redi at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: redi at gcc dot gnu.org @ 2015-03-27 11:36 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Dup

*** This bug has been marked as a duplicate of bug 60943 ***


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

end of thread, other threads:[~2015-03-27 11:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-27 10:55 [Bug c++/65599] New: [c++14] Failing overload resolution when combining return type deduction and explicit R/L-value methods anders at sjogren dot info
2015-03-27 11:36 ` [Bug c++/65599] " redi 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).