 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Matthieu Moy Guest
|
Posted: Tue Jan 25, 2005 3:01 pm Post subject: Templates et valeurs par defaut ... |
|
|
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
|
Posted: Tue Jan 25, 2005 3:07 pm Post subject: Re: Templates et valeurs par defaut ... |
|
|
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
|
Posted: Tue Jan 25, 2005 3:08 pm Post subject: Re: Templates et valeurs par defaut ... |
|
|
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
|
Posted: Tue Jan 25, 2005 3:54 pm Post subject: Re: Templates et valeurs par defaut ... |
|
|
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 |
|
 |
|
|
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
|
|