public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/37043]  New: fails to find operator match when constructing object on the fly
@ 2008-08-06 22:11 scott at stg dot net
  2008-08-06 22:14 ` [Bug c++/37043] " pinskia at gcc dot gnu dot org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: scott at stg dot net @ 2008-08-06 22:11 UTC (permalink / raw)
  To: gcc-bugs

Code below fails with "no match for operator>>", although works in msvc.  If
I'm doing something wrong or there is simple workaround please let me know. 
scott@stg.net.

#include <stdio.h>

class FooBar
{
public:
        FooBar(const char *s)
        {
                printf("Constructed: %s\n",s);
        }
        void Accept(const char *s)
        {
                printf("Passed: %s\n",s);
        }
};

FooBar& operator>> (const char *s,FooBar& dest)
{
        dest.Accept(s);
        return(dest);
}

int main(int argc,char **argv)
{
        FooBar test1("one");

        "A">>test1;

        "B">>FooBar("two");
}


-- 
           Summary: fails to find operator match when constructing object on
                    the fly
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: scott at stg dot net


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


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

* [Bug c++/37043] fails to find operator match when constructing object on the fly
  2008-08-06 22:11 [Bug c++/37043] New: fails to find operator match when constructing object on the fly scott at stg dot net
@ 2008-08-06 22:14 ` pinskia at gcc dot gnu dot org
  2008-08-07 13:32 ` scott at stg dot net
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-08-06 22:14 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2008-08-06 22:13 -------
You cannot bind a rvalue to a reference, only a constant reference or to a non
reference.


-- 


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


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

* [Bug c++/37043] fails to find operator match when constructing object on the fly
  2008-08-06 22:11 [Bug c++/37043] New: fails to find operator match when constructing object on the fly scott at stg dot net
  2008-08-06 22:14 ` [Bug c++/37043] " pinskia at gcc dot gnu dot org
@ 2008-08-07 13:32 ` scott at stg dot net
  2008-08-07 13:55 ` scott at stg dot net
  2008-08-07 15:21 ` schwab at suse dot de
  3 siblings, 0 replies; 5+ messages in thread
From: scott at stg dot net @ 2008-08-07 13:32 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from scott at stg dot net  2008-08-07 13:31 -------
Okay, so if I change:

FooBar& operator>> (const char *s,FooBar& dest)

to

FooBar operator>> (const char *s,FooBar dest)

It now compiles on both msvc and g++, but required functionality (operation
affecting existing object, not making new copy of it) is lost.

Is there some reason that using a reference to rvalue in operator>> is
disallowed in gcc and not msvc?  If so, why doesn't it fail in the A>>object;
instance where the object has already been instantiated separately?


-- 


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


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

* [Bug c++/37043] fails to find operator match when constructing object on the fly
  2008-08-06 22:11 [Bug c++/37043] New: fails to find operator match when constructing object on the fly scott at stg dot net
  2008-08-06 22:14 ` [Bug c++/37043] " pinskia at gcc dot gnu dot org
  2008-08-07 13:32 ` scott at stg dot net
@ 2008-08-07 13:55 ` scott at stg dot net
  2008-08-07 15:21 ` schwab at suse dot de
  3 siblings, 0 replies; 5+ messages in thread
From: scott at stg dot net @ 2008-08-07 13:55 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from scott at stg dot net  2008-08-07 13:53 -------
For clarification, this code compiles & runs in gcc & msvc:
        FooBar test1("one");
        "A">>test1;

And this code compiles & runs fine in msvc, but gives compile error in gcc:
        "B">>FooBar("two");

Since it's the same class, why should there be any difference in matching
operator>> depending on how it's instantiated?

The sample code is a distillation (demonstration) from a larger code base for
convenience of exploring this issue.


-- 


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


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

* [Bug c++/37043] fails to find operator match when constructing object on the fly
  2008-08-06 22:11 [Bug c++/37043] New: fails to find operator match when constructing object on the fly scott at stg dot net
                   ` (2 preceding siblings ...)
  2008-08-07 13:55 ` scott at stg dot net
@ 2008-08-07 15:21 ` schwab at suse dot de
  3 siblings, 0 replies; 5+ messages in thread
From: schwab at suse dot de @ 2008-08-07 15:21 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from schwab at suse dot de  2008-08-07 15:19 -------
Because the result of FooBar("two") is an rvalue, but test1 is an lvalue.


-- 

schwab at suse dot de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


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

end of thread, other threads:[~2008-08-07 15:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-06 22:11 [Bug c++/37043] New: fails to find operator match when constructing object on the fly scott at stg dot net
2008-08-06 22:14 ` [Bug c++/37043] " pinskia at gcc dot gnu dot org
2008-08-07 13:32 ` scott at stg dot net
2008-08-07 13:55 ` scott at stg dot net
2008-08-07 15:21 ` schwab at suse dot de

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