http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54348

--- Comment #9 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-08-22 
07:37:18 UTC ---
(In reply to comment #5)
>       strct s  struct_strct( items, myItems, name, myName ) ;
> }
> </code>
> 
> This works!

Only because NULL can be converted to std::string - but it would crash at
runtime if that branch was taken.


(In reply to comment #7)
> > void f()
> > {
> >     false ? a : b;
> > }
> 
> but this is not the same. surely ? the above is not a valid statement -

It's exactly the same. It's not valid because the types are incompatible, just
like your example. e.g. this is fine:

  false ? a : a;

> I was saying:
> 
>       some_type some_object = false ? a : b;

As I said previously, the fact the conditional expression is used as an
initializer is irrelevant to the error.


(In reply to comment #8)
> All I'm suggesting is that g++ should try to find the most basic error, 

Exactly. And the error is in the conditional expression, it has nothing to do
with the object being initialized.


> which is that different type objects are returned as the result of a
> conditional expression, and not  "no match for ternary 'operator?:'" -
> what does this mean, it was searching namespace std:: for string::operator::?:
> ?
> then this succeeded, and it found it could not apply it because the types
> were different - shouldn't it complain about the root cause, that the types
> were different, rather than the symptom of not being able to satisfy
> operator std::string::?:() ?

It *is* complaining that the types are different (just not very clearly.)
The error has nothing to do with the type being initialized.

Here's a simpler form of your original which might convince you of that:

#include <string>
#include <list>
using namespace std;
void f()
{
      list <string> myItems;
      string myName;
      false ? myItems : myName;
}

This still gives the same error. Understand now?

Reply via email to