Bug 62850 - gcc 3.1-0.23.1 stream inserter lookup fails
Summary: gcc 3.1-0.23.1 stream inserter lookup fails
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Raw Hide
Classification: Retired
Component: gcc3
Version: 1.0
Hardware: i386
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2002-04-06 07:58 UTC by Peter Klotz
Modified: 2008-05-01 15:38 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2002-04-06 07:58:11 UTC
Embargoed:


Attachments (Terms of Use)

Description Peter Klotz 2002-04-06 07:58:07 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:0.9.9) Gecko/20020311

Description of problem:
If the line '#define TWO_INSERTERS' is commented out, the program compiles
without warnings (using -W -Wall) and works as expected, namely writing
'manipulator called' two times.
If the program is compiled as is, one obtains a warning during compile         
(which tells us that the compiler does not use the stream inserter we intend to)
and the program writes 'manipulator called' only once.

gcc 2.96/2.95.3 always compiles without warnings and calls the stream
manipulator twice. Also does the Borland Compiler 5.5.1 and Comeau 4.3Beta2.

Version-Release number of selected component (if applicable):


How reproducible:
Always

Steps to Reproduce:
1. g++3 -W -Wall manip.cpp
2.
3.
	

Actual Results:  During compile:
manip.cpp: In function `void ns::f()':
manip.cpp:28: warning: the address of `void
   ns::manipulator(std::ostringstream&)', will always be `true'

Expected Results:  No warnings and the output 'manipulator called' two times.

Additional info:

#include <iostream>
#include <sstream>

#define TWO_INSERTERS

void operator<<(std::ostream& s, void (*f)(std::ostringstream&))
{
    f(dynamic_cast<std::ostringstream&>(s));
}

namespace ns {

void manipulator(std::ostringstream&)
{
    std::cout << "manipulator called" << std::endl;
}

#ifdef TWO_INSERTERS
std::ostream& operator<<(std::ostream& s, int)
{
	return s;
}
#endif

void f()
{
    std::ostringstream s;
    s << ns::manipulator;
}

} // namespace

int main()
{
    std::ostringstream s;
    s << ns::manipulator;
    ns::f();
    return 0;
}

Comment 1 Jakub Jelinek 2002-04-10 12:45:05 UTC
According to Jason Merrill this is correct.
The big difference between g++ 2.9x and 3.x is honoring of std namespace
which changes things a lot for this testcase.
If you have an inserter in the ns namespace, then standard bool inserter is
chosen.


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