Dependent names in template
Jonathan Wakely
cow@compsoc.man.ac.uk
Thu Aug 5 14:40:00 GMT 2004
Hi,
I've been testing some template code I've written and have found that
although it compiles fine with G++ 3.4 it fails with Comeau's online
compiler. I get an error due to a dependent name not being found during
the first phase of template lookup. In this case my understanding is that
the name lookup should have been delayed until the second-phase since it
is a function call with an argument that is (I believe) a dependent name.
I've simplified the code to that below. The lines in question are marked
ERROR.
The Stream ctor only compiles when std::basic_ios::init() is accessed
through the "this" pointer. Since buf_ is a dependent name, shouldn't
init(&buf_) be treated as dependent also?
Similarly for the call to sputc(c), int_type is dependent, so aren't c
and therefore sputc also dependent ?
Is G++ wrong here? If so is there a bugzilla report already? (I couldn't
find one) Is correcting these tiny corner-cases in G++'s now excellent
parsing on the radar yet?
Thanks for your help understanding this,
jon
-------------- next part --------------
#include <ios>
#include <streambuf>
template <typename CharT, typename Traits = std::char_traits<CharT> >
class Streambuf
: public std::basic_streambuf<CharT,Traits>
{
typedef typename Traits::int_type int_type;
public:
Streambuf() {}
private:
int_type overflow(int_type c) { return sputc(c); } // ERROR with Comeau
};
template <typename CharT, typename Traits = std::char_traits<CharT> >
class Stream
: virtual public std::basic_ios<CharT,Traits>
{
Streambuf<CharT,Traits> buf_;
public:
Stream() : std::basic_ios<CharT,Traits>(NULL), buf_()
{
init(&buf_); // ERROR with Comeau
}
};
int main()
{
Stream<char> s;
}
More information about the Gcc
mailing list