VC++ 7.1 compiler bug with default parameters

J

John Madsen

This bug is easier to just show than to explain I think...

namespace M {
template <class T> struct A {
void f(int a = T::foo()) { } // line 5
};
}

namespace N {
struct B {
static int foo() { return 5; }
};
}

int main() {
M::A<N::B> x;
x.f();
}

VC++ 7.1 (13.10.3077) produces the following diagnostic:
test.cpp(5) : error C2653: 'B' : is not a class or namespace name
test.cpp(5) : error C3861: 'foo': identifier not found, even with
argument-dependent lookup

Taking B out of namespace N makes it work, as does eliminating the
default parameter and providing an overload of A::f with no parameters
(which can serve a general workaround -- although it would be annoying
for constructors).

Both gcc 3.2 and Comeau 4.3.1 compile this code with no problem.

John
 
A

Adam Mitz [MSFT]

Looks like this is a known issue that will be addressed in the next version.
This workaround may be more acceptable:

namespace N {
struct B {
static int foo() { return 5; }
};
}

using namespace N;
namespace M {
template <class T> struct A {
int f(int a = T::foo()) { return a; } // line 5
};
}


int main() {
M::A<N::B> x;
std::cout << x.f();
}

Adam Mitz
Microsoft
--------------------
From: (e-mail address removed) (John Madsen)
Newsgroups: microsoft.public.dotnet.languages.vc
Subject: VC++ 7.1 compiler bug with default parameters
Date: 23 Jul 2003 17:08:17 -0700
Organization: http://groups.google.com/
Lines: 32
Message-ID: <[email protected]>
NNTP-Posting-Host: 24.90.15.235
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: posting.google.com 1059005297 12703 127.0.0.1 (24 Jul 2003 00:08:17 GMT)
X-Complaints-To: (e-mail address removed)
NNTP-Posting-Date: 24 Jul 2003 00:08:17 GMT
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-online.de!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!sn-xit-03! sn-xit-06!sn-xit-01!sn-xit-09!supernews.com!postnews1.google.com!not-for-mail
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vc:26480
X-Tomcat-NG: microsoft.public.dotnet.languages.vc

This bug is easier to just show than to explain I think...

namespace M {
template <class T> struct A {
void f(int a = T::foo()) { } // line 5
};
}

namespace N {
struct B {
static int foo() { return 5; }
};
}

int main() {
M::A<N::B> x;
x.f();
}

VC++ 7.1 (13.10.3077) produces the following diagnostic:
test.cpp(5) : error C2653: 'B' : is not a class or namespace name
test.cpp(5) : error C3861: 'foo': identifier not found, even with
argument-dependent lookup

Taking B out of namespace N makes it work, as does eliminating the
default parameter and providing an overload of A::f with no parameters
(which can serve a general workaround -- although it would be annoying
for constructors).

Both gcc 3.2 and Comeau 4.3.1 compile this code with no problem.

John


--

This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this message are best directed to the newsgroup/thread from which they originated.
 

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