Bug 8700 - [3.2 regression] unhelpful error message for binding temp to reference
|
Bug#:
8700
|
Product: gcc
|
Version: 3.2
|
|
Host:
|
Target:
|
Build:
|
|
Status: RESOLVED
|
Severity: normal
|
Priority: P3
|
|
Resolution: FIXED
|
Assigned To: unassigned@gcc.gnu.org
|
Reported By: adelroy@bloomberg.net
|
|
Component: c++
|
Target Milestone: ---
|
|
Summary: [3.2 regression] unhelpful error message for binding temp to reference
|
|
Keywords:
|
|
Opened: 2002-11-25 07:16
|
Fails to match a unique operator<<, lists two copies as if they were ambiguous
- but the line numbers are the same: definitely only defined once, only happens
for temporary variable.
Get this error compiling following code...
tkrdev1:~dev/tpcc/error_contexts> g++ -o txt txt.cc
txt.cc: In function `int main()':
txt.cc:28: no match for `txt << const char[21]' operator
txt.cc:13: candidates are: txt& operator<<(txt&, const V&) [with V = char[21]]
txt.cc:13: txt& operator<<(txt&, const V&) [with V = char[21]]
zsh: exit 1 g++ -o txt txt.cc
tkrdev1:~dev/tpcc/error_contexts> cat txt.cc
#include <iostream>
#include <sstream>
using namespace std;
class txt
{
ostringstream s;
public:
template<typename V>
friend txt& operator<<(txt& t, const V& v)
{
t.s << v;
return t;
}
operator const char*() { return s.str().c_str(); }
};
int main()
{
txt t;
cout << (t << "hello world!") << endl; // ok
cout << (txt() << "goodbye cruel world!") << endl; //not
return 0;
}
---------------------------
tkrdev1:~dev/tpcc/shmew> g++ -v
Reading specs from /bb/home/adelroy/lib/gcc-lib/sparc-sun-solaris2.8/3.2/specs
Configured with: ../gcc-3.2/configure --prefix=/bb/home/adelroy
--enable-languages=c,c++ --with-ld=/usr/ccs/bin/ld
Thread model: posix
gcc version 3.2
Release:
gcc version 3.2
Environment:
Solaris 2.8 / Sparc
How-To-Repeat:
Try to compile code snippet provided in description.
State-Changed-From-To: open->analyzed
State-Changed-Why: Confirmed. The reason, of course, is that you try to bind
the temporary to a non-const reference. gcc2.95 actually
tells you this:
----------------------------
tmp/g> c++ -c x.cc
x.cc: In function `int main()':
x.cc:28: initialization of non-const reference type `class txt &'
x.cc:28: from rvalue of type `txt'
x.cc:13: in passing argument 1 of `operator <<<char[21]>(txt &, const char (&)[21])'
--------------------------------
The messages we get from 3.2.1 and 3.3 are incomprehensible
compared to that, which I rate as a regression, so I put
this into "high" state and leave it to others whether this
merits fixing.
State-Changed-From-To: analyzed->closed
State-Changed-Why: Fixed for 3.3 and in trunk, and 3.2 branch is now closed.