Bug 41508 - error: no matching function for call to ...
Summary: error: no matching function for call to ...
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.1.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-09-29 18:50 UTC by Marc Warshofsky
Modified: 2009-09-29 20:34 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marc Warshofsky 2009-09-29 18:50:29 UTC
I am currently porting an app from Sun Solaris where we use the Solaris cc compiler (version 5.8). Have a 12 year old legacy app that compiles "fine" in the current environment :-)

While trying to migrate to RedHat Linux and the GNU g++ compiler (version 4.1.2) I am repeatedly running into "error: no matching function for call to ..." errors with code that sends and/or receives reference parameters.

Here's an example of the compiler error:

EJPeriod.C:102: error: no matching function for call to âEJPeriod::EJPeriod(Date&, Date&, String)â
EJPeriod.h:83: note: candidates are: EJPeriod::EJPeriod(EJPeriod&)
EJPeriod.h:76: note:                 EJPeriod::EJPeriod()
EJPeriod.h:72: note:                 EJPeriod::EJPeriod(Date, Date, String&)

I don't understand why the compiler doesn't recognize the 3rd constructor referenced by line 72. When I try to overload the constructor to satisfy the compiler complaint the compiler correctly tells me the two constructors create an ambiguous situation. Can you advise as to whether this is a compiler bug or a potentially old coding standard that isn't acceptable with the version of the GNU compiler we are using?

Also, this only seems to occur with our "home grown" classes. The compiler has no issue with basic scalar types and the passing and receiving of reference and non-reference parameters.

Lastly and admittedly, when I create a simple test.C program to duplicate the issue the simple example compiles. There must be something else in the 1000s of lines of code that I am overlooking.

Thanks in advance for any help or direction you can provide.

Regards,
Marc
Comment 1 Andrew Pinski 2009-09-29 19:15:49 UTC
Can you show the line where the call to EJPeriod::EJPeriod is done?  It might be because String that you are passing is a rvalue which cannot be bound to String& as that would mean it needs to be bound to a lvalue.  rvalues can be bound to const references (or in C++0x rvalue references too).  
Comment 2 Marc Warshofsky 2009-09-29 19:24:23 UTC
This is the method where I am receiving the compiler error:

enum err_stat EJPeriod::rollup( List<EmplJob> &src, List<EJPeriod> &dst,
                                Date &startDt, Date &endDt )
{

// then theres a bunch of code 
// and then the offending line is the one below starting w/EJPeriod

if( srcSize == 1 ) {
    EJPeriod ejptmp( startDt, endDt, src(0)->get_job_title_mgmt_ind() );
    dst.add( new EJPeriod( ejptmp ) );
    return( Success );
   }


The object named "src" is a home grown template linked list class.
Comment 3 Andrew Pinski 2009-09-29 19:25:34 UTC
What type does get_job_title_mgmt_ind return?
Comment 4 Marc Warshofsky 2009-09-29 19:32:31 UTC
Here's the definition for that call ... I think you're on to something

String get_job_title_mgmt_ind() const { return _jobTitleMgmtInd; };

When I change the constructor to "non reference" paramters it seems to compile fine. I've got dozens of these to go through. I suspect they're probably all similar. Is there a better fix than removing the reference parameter? I'm not really sure why the old code  has it as a reference anyway. The constructor is not looking to change that value anyway ... its just using it to initialize a data member.
Comment 5 Andrew Pinski 2009-09-29 19:41:24 UTC
Yes GCC is correct as in C++ rvalues don't bind to references as only lvalues bind to references.
Comment 6 Jakub Jelinek 2009-09-29 20:08:11 UTC
If the ctor isn't going to change it, you could as well change the argument type to const String & instead.
Comment 7 Marc Warshofsky 2009-09-29 20:34:16 UTC
Comment 6 is perfect! That makes total sense. Thanks so much! Actually, I bet the Solaris compiler is implicitly treating this same code as a const & String behind the scenes. We'll just explicitly make that promise/fix for this migration.  Thanks so much for the speedy and excellent responses!!!