This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Error with default arguments?
- To: egcs-bugs at cygnus dot com
- Subject: Error with default arguments?
- From: "Jan D." <jan dot djarv at mbox200 dot swipnet dot se>
- Date: Thu, 27 Nov 1997 19:47:04 +0100 (MET)
Hello.
Using egcs 971122 on Linux 2.1.59, libc 2.0.5.
This is taken straight from the November 1996 working paper for C++:
/*
6 The default arguments in a member function definition that appears
outside of the class definition are added to the set of default argu-
ments provided by the member function declaration in the class defini-
tion. [Example:
*/
class C {
void f(int i = 3);
void g(int i, int j = 99);
};
void C::f(int i = 3) // error: default argument already
{ } // specified in class scope
void C::g(int i = 88, int j) // in this translation unit,
{ } // C::g can be called with no argument
// --end example]
Compiling however does not produce an error:
: jhd; gcc -v -Wall -pedantic x.cc
Reading specs from /usr/lib/gcc-lib/i486-pc-linux-gnu/egcs-2.90.17/specs
gcc version egcs-2.90.17 971114 (gcc2-970802 experimental)
/usr/lib/gcc-lib/i486-pc-linux-gnu/egcs-2.90.17/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -D__GNUC_MINOR__=90 -D__ELF__ -Dunix -Dlinux -D__ELF__ -D__unix__ -D__linux__ -D__unix -D__linux -Asystem(posix) -D__EXCEPTIONS -Wall -pedantic -Di386 -Di486 -Asystem(unix) -Acpu(i386) -Amachine(i386) -D__i386__ -D__i486__ -Asystem(unix) -Acpu(i386) -Amachine(i386) x.cc /tmp/cca00236.iiGNU CPP version egcs-2.90.17 971114 (gcc2-970802 experimental) (i386 Linux/ELF)
: jhd; gcc -c -v -Wall -pedantic x.cc
Reading specs from /usr/lib/gcc-lib/i486-pc-linux-gnu/egcs-2.90.17/specs
gcc version egcs-2.90.17 971114 (gcc2-970802 experimental)
/usr/lib/gcc-lib/i486-pc-linux-gnu/egcs-2.90.17/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -D__GNUC_MINOR__=90 -D__ELF__ -Dunix -Dlinux -D__ELF__ -D__unix__ -D__linux__ -D__unix -D__linux -Asystem(posix) -D__EXCEPTIONS -Wall -pedantic -Di386 -Di486 -Asystem(unix) -Acpu(i386) -Amachine(i386) -D__i386__ -D__i486__ -Asystem(unix) -Acpu(i386) -Amachine(i386) x.cc /tmp/cca00242.iiGNU CPP version egcs-2.90.17 971114 (gcc2-970802 experimental) (i386 Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:
/usr/include/g++
/usr/local/include
/usr/i486-pc-linux-gnu/include
/usr/lib/gcc-lib/i486-pc-linux-gnu/egcs-2.90.17/include
/usr/include
End of search list.
/usr/lib/gcc-lib/i486-pc-linux-gnu/egcs-2.90.17/cc1plus /tmp/cca00242.ii -quiet -dumpbase x.cc -Wall -pedantic -version -o /tmp/cca00242.s
GNU C++ version egcs-2.90.17 971114 (gcc2-970802 experimental) (i486-pc-linux-gnu) compiled by GNU C version egcs-2.90.17 971114 (gcc2-970802 experimental).
x.cc:10: warning: all member functions in class `C' are private
x.cc:12: warning: default argument given for parameter 1 of `void C::f(int = 3)'x.cc:8: warning: after previous specification in `void C::f(int = 3)'
as -V -Qy -o x.o /tmp/cca00242.s
GNU assembler version 970731 (i586-linux), using BFD version linux-2.8.1.0.15
If -pedantic is removed, only the first warning is issued.
I don't have access to the final ISO C++ so this may have changed. If
not the example should not compile.
Regards,
Jan D.