public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: giovannibajo@libero.it
To: gcc-gnats@gcc.gnu.org
Cc: Serge.Bogdanov@intel.com
Subject: c++/10784: [diagnostic] Warning about choosing custom operator over copy constructor cannot be turned off (and it's useless in the first place)
Date: Wed, 14 May 2003 16:16:00 -0000	[thread overview]
Message-ID: <20030514161412.23549.qmail@sources.redhat.com> (raw)


>Number:         10784
>Category:       c++
>Synopsis:       [diagnostic] Warning about choosing custom operator over copy constructor cannot be turned off (and it's useless in the first place)
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed May 14 16:16:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Giovanni Bajo
>Release:        3.0 -> 3.4
>Organization:
>Environment:
i686-pc-cygwin
>Description:
This was originally c++/4337, but I opened a new PR to make
it clearer.

--------------------------------
#include <stdio.h>

struct A {
};
struct A1 : public A {

    A1(const A &) {
        printf("A1(const A &)\n");
    }
    A1() {
        printf("A1()\n");
    }
};
A1 X;
struct A2 : public A {
    operator A1() {
        printf("operator A1()\n");
        return X;
    }
};

int main()
{
    A2 a2;
    A1 a1;
    a1 = a2;
}
--------------------------------
pr4337.cpp: In function `int main()':
pr4337.cpp:26: warning: choosing `A2::operator A1()' over `A1::A1(const A&)'
pr4337.cpp:26: warning:   for conversion from `A2' to `A1'
pr4337.cpp:26: warning:   because conversion sequence for the argument is better

GCC has always emitted the previous warning since at least
2.95. There is no (known?) way to turn it off, and it
breaks compilation. Besides, the code is not ambigous,
I think that the compiler should always select the custom
conversion operator, so there is nothing to warn about.
The output is:

A1()
A1()
operator A1()

and every compiler I have gives the same output.

Such a warning should be moved to -Wextra, if kept at all.
>How-To-Repeat:
Compile the above snippet.
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


             reply	other threads:[~2003-05-14 16:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-14 16:16 giovannibajo [this message]
2003-05-14 16:24 giovannibajo
2003-05-15  4:36 Gabriel Dos Reis
2003-05-15  4:47 bangerth

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=20030514161412.23549.qmail@sources.redhat.com \
    --to=giovannibajo@libero.it \
    --cc=Serge.Bogdanov@intel.com \
    --cc=gcc-gnats@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).