BUG VC7.1: in class friend template function definition does not have access to the class's template

  • Thread starter Maxim Yegorushkin
  • Start date
M

Maxim Yegorushkin

I have a template class and a friend template function definition in the definition of the class. The problem is that the function's declaration has access to the class's template parameters but the function's body (definition) does not.

I believe that the function's body must have the access according to the standard [11.4.5]: A friend function defined in a class is in the (lexical) scope of the class in which it is defined. A friend function defined outside the class is not (3.4.1).

VC7.1 conforms to the standard when a friend function is not templated and does not conform otherwise.

The following code snippet, perfectly compilable with Comeau online, Intel C++ Compiler 8.0, gcc 3.2, produces an error when compiled with MS VC7.1.

Does anybody have explanation for VC's behavior?

#include <iostream>
#include <ctime>

namespace util
{

template<class derived_t>
struct io_manipulator_concept
{
template<class T, class U>
friend std::basic_ostream<T, U>& operator<<(
std::basic_ostream<T, U>& stream
, io_manipulator_concept<derived_t> const& manip
)
{
static_cast<derived_t const&>(manip).out(stream); // error C2061: syntax error : identifier 'derived_t'
return stream;
}
};

} // namespace util {

struct time_manipulator_model : util::io_manipulator_concept<time_manipulator_model>
{
void out(std::blush:stream& stream) const
{
time_t t;
std::time(&t);
stream << std::ctime(&t);
}
} time_manip;

int main()
{
std::cout << time_manip << '\n';
}
 
C

Carl Daniel [VC++ MVP]

Maxim said:
I have a template class and a friend template function definition in
the definition of the class. The problem is that the function's
declaration has access to the class's template parameters but the
function's body (definition) does not.

I believe that the function's body must have the access according to
the standard [11.4.5]: A friend function defined in a class is in the
(lexical) scope of the class in which it is defined. A friend
function defined outside the class is not (3.4.1).

VC7.1 conforms to the standard when a friend function is not
templated and does not conform otherwise.

The following code snippet, perfectly compilable with Comeau online,
Intel C++ Compiler 8.0, gcc 3.2, produces an error when compiled with
MS VC7.1.

Does anybody have explanation for VC's behavior?

It's a known bug. I don't know if it's going to be fixed in Whidbey, but I
think that it is not. I'll try it out with the most recent Whidbey alpha
when I get a chance (don't have it installed on this computer).

-cd
 
M

Maxim Yegorushkin

Carl Daniel said:
It's a known bug. I don't know if it's going to be fixed in Whidbey, but I
think that it is not. I'll try it out with the most recent Whidbey alpha
when I get a chance (don't have it installed on this computer).

Is there any VC7.1 bug list? It would save me from wasting time.
 
C

Carl Daniel [VC++ MVP]

Maxim said:
Carl Daniel [VC++ MVP]
It's a known bug. I don't know if it's going to be fixed in
Whidbey, but I think that it is not. I'll try it out with the most
recent Whidbey alpha when I get a chance (don't have it installed on
this computer).

Is there any VC7.1 bug list? It would save me from wasting time.

No, there isn't :(

-cd
 
M

Maxim Yegorushkin

Carl Daniel said:
No, there isn't :(

Aha, looks like our beloved company wants to keep its "highly conformant with the ISO C++ language definition... with advanced template features defined by the ISO standard" compiler bugs as a secreet :). Well, at least, sounds microsoft stylish...
 
C

Carl Daniel [VC++ MVP]

Maxim said:
Aha, looks like our beloved company wants to keep its "highly
conformant with the ISO C++ language definition... with advanced
template features defined by the ISO standard" compiler bugs as a
secreet :). Well, at least, sounds microsoft stylish...

I'd say that it's nothing quite so sinister. The bugs are tracked in an
in-house database and they don't have an effective and manageable way to
expose that database to end users. This is a problem they're aware of, but
AFIAK nothing has been announced in the way of a publicly-accessible bug
database. You never know what tomorrow will bring though.

-cd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top