[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 gcc-bugzilla@gcc.gnu.org
Tue Aug 21 19:28:00 GMT 2012


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 ?



More information about the Gcc-bugs mailing list