public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "m.cencora at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/113219] New: Overloaded ref-qualified conversion operator triggers bogus -Wconversion
Date: Wed, 03 Jan 2024 16:38:09 +0000	[thread overview]
Message-ID: <bug-113219-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 113219
           Summary: Overloaded ref-qualified conversion operator triggers
                    bogus -Wconversion
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: m.cencora at gmail dot com
  Target Milestone: ---

Following code when compiled on any gcc version (checked all available on
godbolt since gcc-7) triggers conversion warnings.
I consider it bogus because it tells user that it has chosen a better overload
(which is good thing, right?).
Clang doesn't print any related warning even with -Weverything

g++ -std=c++17 -Wconversion

template <typename T>
struct wrapper
{
    operator T() const&;

    operator T&&() &&;
};

wrapper<int> createInt();

int test()
{
    return createInt();
}

Output is:
<source>:13:21: warning: choosing 'wrapper<T>::operator T&&() && [with T =
int]' over 'wrapper<T>::operator T() const & [with T = int]' [-Wconversion]
   13 |     return createInt();
      |            ~~~~~~~~~^~
<source>:13:21: warning:   for conversion from 'wrapper<int>' to 'int'
[-Wconversion]
<source>:13:21: note:   because conversion sequence for the argument is better

             reply	other threads:[~2024-01-03 16:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-03 16:38 m.cencora at gmail dot com [this message]
2024-01-03 21:58 ` [Bug c++/113219] " pinskia at gcc dot gnu.org
2024-01-04  8:17 ` m.cencora at gmail dot com

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