public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jason.vas.dias at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
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	[thread overview]
Message-ID: <bug-54348-4@http.gcc.gnu.org/bugzilla/> (raw)

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:

<code>
#include <string>
#include <list>
using namespace std;
void f()
{
      struct strct { string name, items ;};
      list <string> myItems;
      string myName("");
      string as      ( (   (&(((strct*)0)  -> items)) 
            == (&(((strct*)0) -> name))
               ) ? myItems 
                 : myName
             )
             ;
}
</code>

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 <string> myItems' to 'string myItems' allows compilation
to succeed.

Shouldn't g++ be complaining about initializing a string with a list<string>
rather than this cryptic "no match for ternary 'operator?:'" here ?


             reply	other threads:[~2012-08-21 19:28 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-21 19:28 jason.vas.dias at gmail dot com [this message]
2012-08-21 19:45 ` [Bug c++/54348] confusing " paolo.carlini at oracle dot com
2012-08-21 19:52 ` redi at gcc dot gnu.org
2012-08-21 20:08 ` paolo.carlini at oracle dot com
2012-08-21 20:24 ` redi at gcc dot gnu.org
2012-08-21 20:27 ` jason.vas.dias at gmail dot com
2012-08-21 20:30 ` jason.vas.dias at gmail dot com
2012-08-21 20:34 ` jason.vas.dias at gmail dot com
2012-08-21 20:52 ` jason.vas.dias at gmail dot com
2012-08-22  7:38 ` redi at gcc dot gnu.org
2014-05-09 18:16 ` jason at gcc dot gnu.org
2014-05-09 18:21 ` jason 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-54348-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).