Bug 37760 - wrong error message no matching function when using not const copy constructor
wrong error message no matching function when using not const copy constructor
Status: CLOSED NOTABUG
Product: Red Hat Linux
Classification: Retired
Component: gcc (Show other bugs)
7.0
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
David Lawrence
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2001-04-26 06:44 EDT by cizaire
Modified: 2007-04-18 12:32 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2001-04-26 06:44:08 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description cizaire 2001-04-26 06:44:05 EDT
From Bugzilla Helper:
User-Agent: Mozilla/4.76 [en] (WinNT; U)


// file test.cc
#include <stdio.h>

class TKeeped;
class TKeeper
{
  TKeeped &keeped;

  void Init(void);
  void Reset(void);
public:
  TKeeped &Keeped(void) { return keeped; }

  TKeeper(TKeeped &_keeped) : keeped(_keeped) { Init(); }
  ~TKeeper(void) { Reset(); }

  TKeeper(TKeeper &keeper) : keeped(keeper.Keeped()) { Init(); }

private:
  static int created;
public:
  static int Created(void) { return created; }
};

class TKeeped
{
  int count;
public:
  TKeeped(void);
  ~TKeeped(void);

  static TKeeper New(void);
private:
  friend TKeeper;
  void KeeperAdd(void);
  void KeeperRemove(void);
};

int TKeeper::created = 0;

void TKeeper::Init(void) 
{ 
  ++created;
  printf("TKeeper[%08X](TKeeped[%08X])::Init (%d)\n", 
	 this, &Keeped(), created); 
  Keeped().KeeperAdd(); 
}

void TKeeper::Reset(void)
{
  printf("TKeeper[%08X](TKeeped[%08X])::Reset\n", this, &Keeped()); 
  Keeped().KeeperRemove();
}

TKeeped::TKeeped(void) : 
  count(0) 
{ 
  printf("TKeeped[%08X]\n", this); 
}

TKeeped::~TKeeped(void) 
{ 
  printf("~TKeeped[%08X]\n", this); 
}

void TKeeped::KeeperAdd(void) 
{ 
  printf("TKeeped[%08X](%d)::++\n", this, count);
  ++count; 
}

void TKeeped::KeeperRemove(void) 
{ 
  printf("TKeeped[%08X](%d)::--\n", this, count);
  if(--count) return;
  delete this;
}

TKeeper TKeeped::New(void)
{
  return TKeeper(* new TKeeped); 
}

int main(void)
{
  {
    printf("before\n");
    TKeeper keeper(TKeeped::New());
    printf("after\n");
  }
  printf("out of scope\n");
  printf("total keeper created : %d\n", TKeeper::Created());
}


Reproducible: Always
Steps to Reproduce:
1. g++ -o test test.cc
	

Actual Results:  test.cc: In function `TKeeper TKeeped::New ()':
test.cc:80: no matching function for call to `TKeeper::TKeeper 
(TKeeper)'
test.cc:13: candidates are: TKeeper::TKeeper (TKeeped &)
test.cc:16:                 TKeeper::TKeeper (TKeeper &)
test.cc: In function `int main ()':
test.cc:87: no matching function for call to `TKeeper::TKeeper 
(TKeeper)'
test.cc:13: candidates are: TKeeper::TKeeper (TKeeped &)
test.cc:16:                 TKeeper::TKeeper (TKeeper &)


Expected Results:  before
TKeeped[00024AB0]
TKeeper[EFFFF7B8](TKeeped[00024AB0])::Init (1)
TKeeped[00024AB0](0)::++
after
TKeeper[EFFFF7B8](TKeeped[00024AB0])::Reset
TKeeped[00024AB0](1)::--
~TKeeped[00024AB0]
out of scope
total keeper created : 1


There where warnings on RH 6.2 with egc-2.91.66 but it compiled and works fine
Comment 1 Jakub Jelinek 2001-04-26 06:53:30 EDT
The error is correct, you're trying to pass a temporary, not variable by
reference. You cannot do that.
egcs 1.1.2 is very far from what C++ standard sais, so if it accepts something
it does not mean it is correct C++.
Comment 2 cizaire 2001-04-26 08:12:25 EDT
Can you help me by telling me what is the correct way to acheive what I am trying to do ?
The point is that I didn't find any solution to work around this problem except some very dirty casts that creates some
more temporaries. 
Do I need to stay with old egcs or there is some special flags to tell g++ that a temporary in *not* const...

Note You need to log in before you can comment on or make changes to this bug.