From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23914 invoked by alias); 21 Aug 2012 19:28:16 -0000 Received: (qmail 23889 invoked by uid 22791); 21 Aug 2012 19:28:15 -0000 X-SWARE-Spam-Status: No, hits=-3.6 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 21 Aug 2012 19:28:02 +0000 From: "jason.vas.dias at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/54348] New: wrong error reported for type mismatch in conditional expression : "error: no match for ternary 'operator?:' in 'false ?" Date: Tue, 21 Aug 2012 19:28:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Keywords: X-Bugzilla-Severity: enhancement X-Bugzilla-Who: jason.vas.dias at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-08/txt/msg01496.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54348 Bug #: 54348 Summary: wrong error reported for type mismatch in conditional expression : "error: no match for ternary 'operator?:' in 'false ?" Classification: Unclassified Product: gcc Version: 4.6.0 Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: c++ AssignedTo: unassigned@gcc.gnu.org ReportedBy: jason.vas.dias@gmail.com Having made the simple mistake of returning an object of a different type in the '? ( ... )' and ': ( ... )' clauses of a ternary expression , I'd expect and it would be helpful if g++ would emit the "C" error "error: type mismatch in conditional expression" and not "error: no match for ternary 'operator?:' in 'false ? ..." This is extremely confusing, as it suggests that the ternary expression somehow contains an unbalanced number of parentheses or something. This code triggers the issue: #include #include using namespace std; void f() { struct strct { string name, items ;}; list myItems; string myName(""); string as ( ( (&(((strct*)0) -> items)) == (&(((strct*)0) -> name)) ) ? myItems : myName ) ; } Compilation with gcc-4.6.0 & gcc-4.6.3 returns this error: $ g++ -c gxx_bug.cpp gxx_bug.cpp: In function 'void f()': gxx_bug.cpp:12:14: error: no match for ternary 'operator?:' in 'false ? myItems : myName' whereas changing 'list myItems' to 'string myItems' allows compilation to succeed. Shouldn't g++ be complaining about initializing a string with a list rather than this cryptic "no match for ternary 'operator?:'" here ?