(3.4.2 Bug?) Copy ctor needed to pass temporary as const reference?

Faschingbauer jfasch@salomon.at
Sat Sep 11 10:25:00 GMT 2004


The following code does not compile with gcc 3.4.2 (OS is Redhat 7.2
on a 386, if it matters),

class NotCopyable {
public:
   NotCopyable();
private:
   NotCopyable(const NotCopyable&);
   NotCopyable& operator=(const NotCopyable&);
};

void f(const NotCopyable&);

void g() {
    f(NotCopyable());
}

$ ~/installed-packages/gcc-3.4.2/bin/g++ -c bug.cc 
bug.cc: In function `void g()':
bug.cc:5: Fehler: `NotCopyable::NotCopyable(const NotCopyable&)' is private
bug.cc:10: Fehler: within this context

I use to pass temporaries as const references quite often in my
code. What puzzles me is that a copy appears to be made.

Is that a bug in gcc or am I missing something?

Joerg



More information about the Gcc mailing list