Re: Comeau vs gcc - specifying a type which is dependent on a template parameter
On Aug 27, 2:40 pm, Paul <paulrobinso...@googlemail.com> wrote:
The code below compiles fine on Comeau under all the versions
available onhttp://www.comeaucomputing.com/tryitout/
template <class T>
class Foo {
public:
typedef double return_type;
return_type bar();
};
template <class T>
Foo<T>::return_type Foo<T>::bar() {
return 4.0;
}
template class Foo<int>;
However when compiling with gcc (4.3.2), the following error occurs:
:9: error: expected constructor, destructor, or type conversion before
'Foo'
It can be easily fixed by adding in a 'typename' before the return
type on line 9 such that it is:
typename Foo<T>::return_type Foo<T>::bar() {
However since this works with Comeau, is this a case of gcc being too
strict? is this a bug in gcc?
Issue #224 "Definition of dependent names" resolved this issue for the
2003 C++ Standard, In short, there should be no "typename" in front of
bar()'s return type, because the name of the return type,
"return_type" (in this case) is a member of the "current
instantiation".
Unfortunately, the wording about the "current instantiation" was
accidentally deleted from the current draft when Issue #382 "Allow
'typename' outside of templates" was resolved. See Issue #559 "Editing
error in issue 382 resolution":
http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2009/n2937.html#559
However, this issue is far from settled. Even Greg Comeau questions
whether a C++ compiler can reliably parse a function definition such
as Foo<T>::bar() unless there is a "typename" before "return_type."
See issue #560 "Use of the 'typename' keyword in return types".
http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2009/n2816.html#560
Greg
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]