Home Dashboard Directory Help

Visual C++ does not permit befriending the constructor of a base class that is a template specialization by James McNellis


 as Fixed Help for as Fixed

Sign in
to vote
Type: Bug
ID: 558796
Opened: 5/12/2010 7:19:46 PM
Access Restriction: Public
User(s) can reproduce this bug


Given the following code,

    template<typename T>
    struct B

    class A : public B<int>
        friend B<int>::B();

Visual C++ 2010 reports the following errors:

    test.cpp(9): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    test.cpp(9): error C2935: 'B<T>' : template-class-id redefined as a global function with [ T=int ]

If class A is declared without B<int> as a base, there are no errors. Likewise, if the (invalid) friend declaration

    friend B<int>::B<int>();

is used, no error is reported. That friend declaration is invalid according to the resolution of CWG defect 147, http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#147. That resolution was incorporated into the C++03 standard.

Comeau, Intel C++ 11.1, and gcc 4.5 and later all accept the code without error.

This defect is reported in conjunction with the following question on StackOverflow: http://stackoverflow.com/questions/2823485/how-to-befriend-a-templated-classs-constructor
Sign in to post a comment.
Posted by James McNellis on 5/28/2010 at 4:28 PM
Unless, of course, it's been fixed for the next build, in which case my previous comment just proves I'm an idiot. :-) Sorry about that.
Posted by James McNellis on 5/20/2010 at 5:04 PM
Saying "indeed this is a bug in our compiler" and then suggesting as a workaround something that is invalid by the language standard is a queer definition of "fixed."

I understand that this is likely not a high-priority issue, but saying that some thing is fixed when it is not is frustrating.
Posted by James McNellis on 5/20/2010 at 5:01 PM
Right; I am aware of the nonstandard workaround. I mentioned that workaround in the problem description.

However, a nonstandard, syntactically ill-formed workaround makes for code that is not portable. For some of us, portability is extraordinarily important.
Posted by Microsoft on 5/20/2010 at 3:39 PM

Thank you for your feedback. Indeed this is a bug in our compiler, however there's a trivial non-standard workaround you could use.

template<typename T>
struct B
    A a;
    a.foo = 34;

class A : public B<int>
friend B<int>::B<int>();

int foo;

int main()
    B<int> b;

Ulzii Luvsanbat
Windows C++ Team
Posted by Microsoft on 5/13/2010 at 4:02 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.