public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/54348] New: wrong error reported for type mismatch in conditional expression : "error: no match for ternary 'operator?:' in 'false ?"
@ 2012-08-21 19:28 jason.vas.dias at gmail dot com
  2012-08-21 19:45 ` [Bug c++/54348] confusing " paolo.carlini at oracle dot com
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: jason.vas.dias at gmail dot com @ 2012-08-21 19:28 UTC (permalink / raw)
  To: gcc-bugs

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 ?


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2014-05-09 18:21 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-21 19:28 [Bug c++/54348] New: wrong error reported for type mismatch in conditional expression : "error: no match for ternary 'operator?:' in 'false ?" jason.vas.dias at gmail dot com
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

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