Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / June 2004

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Maxim Yegorushkin - 05 Jun 2004 17:02 GMT
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::ostream& stream) const
    {
        time_t t;
        std::time(&t);
        stream << std::ctime(&t);
    }
} time_manip;

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

Signature

Maxim Yegorushkin

Carl Daniel [VC++ MVP] - 05 Jun 2004 17:19 GMT
> I have a template class and a friend template function definition in
> the definition of the class. The problem is that the function's
[quoted text clipped - 14 lines]
>
> 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
Maxim Yegorushkin - 05 Jun 2004 18:07 GMT
> 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.

Signature

Maxim Yegorushkin

Carl Daniel [VC++ MVP] - 06 Jun 2004 00:52 GMT
> Carl Daniel [VC++ MVP]
> <cpdaniel_remove_this_and_nospam@mvps.org.nospam> wrote:
[quoted text clipped - 5 lines]
>
> Is there any VC7.1 bug list? It would save me from wasting time.

No, there isn't :(

-cd
Maxim Yegorushkin - 06 Jun 2004 01:10 GMT
>> Is there any VC7.1 bug list? It would save me from wasting time.
>
> 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...

Signature

Maxim Yegorushkin

Carl Daniel [VC++ MVP] - 06 Jun 2004 02:56 GMT
> 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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.