* function template specialization problem
@ 2006-03-21 19:13 rodolfo
2006-03-21 19:47 ` Andrew Haley
2006-03-21 22:10 ` Daniel Llorens del Río
0 siblings, 2 replies; 3+ messages in thread
From: rodolfo @ 2006-03-21 19:13 UTC (permalink / raw)
To: gcc-help
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=us-ascii, Size: 847 bytes --]
Hi, I don't know if this is a C++ or g++ problem, but this snippet
doesn't compile, but I think it should:
template <class T> void test(const char *par);
template <> void test<int>(const char *par = 0) {}
int main()
{
test<int>();
}
g++ 3.4.5 returns the following errors:
test.cpp:3: error: default arguments are only permitted for function parameters
test.cpp:7: error: no matching function for call to `test()'
Well, the first error text is a little bit misleading because I'm
defining a default argument for a function parameter, but somehow this
is not parsed correctly, and g++ thinks it's not a function.
So, is this allowed in c++ or is a g++ parse bug?
Thanks,
Rodolfo Lima.
_______________________________________________________
Yahoo! doce lar. Faça do Yahoo! sua homepage.
http://br.yahoo.com/homepageset.html
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: function template specialization problem
2006-03-21 19:13 function template specialization problem rodolfo
@ 2006-03-21 19:47 ` Andrew Haley
2006-03-21 22:10 ` Daniel Llorens del Río
1 sibling, 0 replies; 3+ messages in thread
From: Andrew Haley @ 2006-03-21 19:47 UTC (permalink / raw)
To: rodolfo; +Cc: gcc-help
rodolfo@rodsoft.org writes:
> Hi, I don't know if this is a C++ or g++ problem, but this snippet
> doesn't compile, but I think it should:
>
> template <class T> void test(const char *par);
>
> template <> void test<int>(const char *par = 0) {}
>
> int main()
> {
> test<int>();
> }
>
> g++ 3.4.5 returns the following errors:
> test.cpp:3: error: default arguments are only permitted for function parameters
> test.cpp:7: error: no matching function for call to `test()'
>
> Well, the first error text is a little bit misleading because I'm
> defining a default argument for a function parameter, but somehow this
> is not parsed correctly, and g++ thinks it's not a function.
>
> So, is this allowed in c++ or is a g++ parse bug?
No. See Section 14.7.3, Para. 21.
"Default function arguments shall not be specified in the explicit
specialization of a function template."
Andrew.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: function template specialization problem
2006-03-21 19:13 function template specialization problem rodolfo
2006-03-21 19:47 ` Andrew Haley
@ 2006-03-21 22:10 ` Daniel Llorens del Río
1 sibling, 0 replies; 3+ messages in thread
From: Daniel Llorens del Río @ 2006-03-21 22:10 UTC (permalink / raw)
To: gcc-help
On 21 Mar, 2006, at 20:16, rodolfo@rodsoft.org wrote:
> Hi, I don't know if this is a C++ or g++ problem, but this snippet
> doesn't compile, but I think it should:
>
> template <class T> void test(const char *par);
>
> template <> void test<int>(const char *par = 0) {}
>
> int main()
> {
> test<int>();
> }
>
> g++ 3.4.5 returns the following errors:
> test.cpp:3: error: default arguments are only permitted for
> function parameters
> test.cpp:7: error: no matching function for call to `test()'
The first error message is unclear, but the code is illegal anyway.
You cannot declare a default parameter in a specialization. You must
declare it in the function template declaration, and only there.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2006-03-21 22:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-03-21 19:13 function template specialization problem rodolfo
2006-03-21 19:47 ` Andrew Haley
2006-03-21 22:10 ` Daniel Llorens del Río
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).