C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Templates et valeurs par defaut ...

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (French)
View previous topic :: View next topic  
Author Message
Matthieu Moy
Guest





PostPosted: Tue Jan 25, 2005 3:01 pm    Post subject: Templates et valeurs par defaut ... Reply with quote



Bonjour,

On vient de me soumettre une bizarerie que je n'arrive pas a
expliquer.

Le code suivant compile avec GCC 3.4.1, en -ansi -pedantic -Wall :

#include <stdlib.h>
//#define T int

#ifndef T
template<class T>
#endif
T f2(const char * s2, T arg2, T arg3);

#ifndef T
template<class T>
#endif
T f2(const char * s2 = NULL, T arg2, T arg3) {
return (s2)?arg2:arg3;
}

int main() {
f2(NULL, 0, 0);
}


La bizarerie, c'est la valeur par défaut de s2 dans l'implémentation
de f2. Si on n'utilise pas de template (en décommentant le #define),
GCC sort un

default.cpp: In function `int f2(const char*, int, int)':
default.cpp:12: error: default argument missing for parameter 2 of `int f2(const char*, int, int)'

Que je trouve bien plus logique.

Est-ce un bug de GCC ? Si non, comment utilise-t-on ces choses ?

Merci,

--
Matthieu
Back to top
Jean-Marc Bourguet
Guest





PostPosted: Tue Jan 25, 2005 3:07 pm    Post subject: Re: Templates et valeurs par defaut ... Reply with quote



Matthieu Moy <MatthieuNOSPAM.Moy (AT) imag (DOT) fr.invalid> writes:

Quote:
Est-ce un bug de GCC ?

Je le crois; je ne vois pas un moyen d'utiliser ca ni pourquoi si
c'etait possible on ne pourrait l'utiliser en dehors des template.
Pour info Como (http://www.comeaucomputing.com/pcgi-bin/compiler.html)
sort:

"ComeauTest.c", line 11: error: specifying a default argument when redeclaring an
unreferenced function template is nonstandard
T f2(const char * s2 = NULL, T arg2, T arg3) {
^

"ComeauTest.c", line 11: error: default argument not at end of parameter list
T f2(const char * s2 = NULL, T arg2, T arg3) {
^

2 errors detected in the compilation of "ComeauTest.c".

A+

--
Jean-Marc
FAQ de fclc++: http://www.cmla.ens-cachan.fr/~dosreis/C++/FAQ
C++ FAQ Lite en VF: http://www.ifrance.com/jlecomte/c++/c++-faq-lite/index.html
Site de usenet-fr: http://www.usenet-fr.news.eu.org

Back to top
Gabriel Dos Reis
Guest





PostPosted: Tue Jan 25, 2005 3:08 pm    Post subject: Re: Templates et valeurs par defaut ... Reply with quote



Matthieu Moy <MatthieuNOSPAM.Moy (AT) imag (DOT) fr.invalid> writes:

[...]

Quote:
Est-ce un bug de GCC ? Si non, comment utilise-t-on ces choses ?

C'est un bug de GCC. Quelqu'un a dupliqué du code et a fait n'importe
quoi. Peux-tu faire un bug report, s'il te plaît ?

-- Gaby

Back to top
Matthieu Moy
Guest





PostPosted: Tue Jan 25, 2005 3:54 pm    Post subject: Re: Templates et valeurs par defaut ... Reply with quote

Gabriel Dos Reis <gdr (AT) integrable-solutions (DOT) net> writes:

Quote:
C'est un bug de GCC. Quelqu'un a dupliqué du code et a fait n'importe
quoi. Peux-tu faire un bug report, s'il te plaît ?

C'était bien mon intention.

--
Matthieu

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (French) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.