This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Bug: missing endl


Geoffrey Furnish wrote:
> 
> llewelly@edevnull.com writes:
>  > Geoffrey Furnish <furnish@actel.com> writes:
>  >
>  > > The following looks like a bug to me, discovered in 20000821 snapshot:


I believe this occurs in 2.95.2 as well. The compiler seems to have some
trouble with the using directive in local scope (not sure if templates
have anything to do with it). Here's a simple test case.

Regards
Martin

$ cat tets.cpp

namespace N {

template <class T>
struct S { };

template <class T>
S<T> foo (const S<T> &s) { return s; }

template <class T>
S<T> operator<< (const S<T> &s, S<T>(*)(const S<T>&))
{
    return s;
}

template <class T>
S<T> foobar (const S<T> &s) { return s; }

}

template <class T>
void bar () {
    using namespace N;

    foo(S<T>()) << foobar;
}

int main ()
{
    bar<int>();
}

$ g++ test.cpp -c
test.cpp: In function `void bar<int>()':
test.cpp:31:   instantiated from here
test.cpp:26: `foobar' undeclared (first use this function)
test.cpp:26: (Each undeclared identifier is reported only once
test.cpp:26: for each function it appears in.)


>  > >
>  > > valinux[69] cat y.cc
>  > > #include <iostream>
>  > >
>  > > namespace A {
>  > >
>  > >     template<class B>
>  > >     class XYZ {
>  > >       public:
>  > >         void compute();
>  > >     };
>  > >
>  > >     template<class B>
>  > >     void XYZ<B>::compute()
>  > >     {
>  > >         using namespace std;      <---------------+
>  > >                                                   |
>  > >         cout << "Testing." << endl;               |
>  >                                                     |
>  > cout and endl have been moved into std::.           |
>  >                                                     |
>  > Try:                                                |
>  >           std::cout << "Testing." << std::endl;     |
>  >                                                     |
>  > or add appropriate using declarations.              |
>                                                        |
> Please read the code again more carefully.  -----------+
> 
>  > >     }
>  > >
>  > > }
>  > >
>  > > namespace A {
>  > >     template class XYZ<int>;
>  > > }
>  > > valinux[70] c++ -v -c y.cc
>  > > Reading specs from /va1/furnish/gcc/lib/gcc-lib/i686-pc-linux/2.96/specs
>  > > gcc version 2.96 20000821 (experimental)
>  > >  /va1/furnish/gcc/lib/gcc-lib/i686-pc-linux/2.96/cpp0 -lang-c++ -D__GNUG__=2 -v -D__GNUC__=2 -D__GNUC_MINOR__=96 -D__GNUC_PATCHLEVEL__=0 -D__ELF__ -Dunix -Dlinux -D__ELF__ -D__unix__ -D__linux__ -D__unix -D__linux -Asystem(posix) -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ -D__tune_pentiumpro__ y.cc /tmp/ccaxMWTc.ii
>  > > GNU CPP version 2.96 20000821 (experimental) (cpplib)
>  > >  (i386 Linux/ELF)
>  > > ignoring nonexistent directory "/usr/local/include"
>  > > #include "..." search starts here:
>  > > #include <...> search starts here:
>  > >  /va1/furnish/gcc/include/g++-v3
>  > >  /va1/furnish/gcc/lib/gcc-lib/i686-pc-linux/2.96/include
>  > >  /va1/furnish/gcc/i686-pc-linux/include
>  > >  /usr/include
>  > > End of search list.
>  > >  /va1/furnish/gcc/lib/gcc-lib/i686-pc-linux/2.96/cc1plus /tmp/ccaxMWTc.ii -quiet -dumpbase y.cc -version -o /tmp/cc98EJPi.s
>  > > GNU C++ version 2.96 20000821 (experimental) (i686-pc-linux) compiled by GNU C version 2.96 20000821 (experimental).
>  > > y.cc: In method `void A::XYZ<B>::compute () [with B = int]':
>  > > y.cc:22:   instantiated from here
>  > > y.cc:16: `endl' undeclared (first use this function)
>  > > y.cc:16: (Each undeclared identifier is reported only once for each function it
>  > > appears in.)
>  > > valinux[71]
>  > >
>  > > I don't know if it matters, but this snapshot was configured with
>  > > --enable-libstdcxx-v3 --enable-shared.
>  >
>  > It does matter. --enable-libstdcxx-v3 configures the compiler so that
>  >   -fhonor-std is always on, and the standard library so that it is
>  >   nicely wrapped in std::, the way it is supposed to be.
>  >
>  >
>  > Thank you for your bug report.
>  > [snip]
>  >
> 
> cout was seen, endl wasn't.  As I said, it looks like a bug (in gcc)
> to me.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]