public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "anders at sjogren dot info" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/65599] New: [c++14] Failing overload resolution when combining return type deduction and explicit R/L-value methods
Date: Fri, 27 Mar 2015 10:55:00 -0000	[thread overview]
Message-ID: <bug-65599-4@http.gcc.gnu.org/bugzilla/> (raw)

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


             reply	other threads:[~2015-03-27 10:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-27 10:55 anders at sjogren dot info [this message]
2015-03-27 11:36 ` [Bug c++/65599] " redi at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-65599-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).