From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27682 invoked by alias); 14 May 2003 16:16:01 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 27622 invoked by uid 71); 14 May 2003 16:16:00 -0000 Resent-Date: 14 May 2003 16:16:00 -0000 Resent-Message-ID: <20030514161600.27620.qmail@sources.redhat.com> Resent-From: gcc-gnats@gcc.gnu.org (GNATS Filer) Resent-Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org, Serge.Bogdanov@intel.com Resent-Reply-To: gcc-gnats@gcc.gnu.org, giovannibajo@libero.it Received: (qmail 23550 invoked by uid 48); 14 May 2003 16:14:12 -0000 Message-Id: <20030514161412.23549.qmail@sources.redhat.com> Date: Wed, 14 May 2003 16:16:00 -0000 From: giovannibajo@libero.it Reply-To: giovannibajo@libero.it To: gcc-gnats@gcc.gnu.org Cc: Serge.Bogdanov@intel.com X-Send-Pr-Version: gnatsweb-2.9.3 (1.1.1.1.2.31) X-GNATS-Notify: 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) X-SW-Source: 2003-05/txt/msg01655.txt.bz2 List-Id: >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 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: