[Bug c++/29177] New: Wrongly rejects non-template function default arguments in later declarations

greifel at megatop200 dot com gcc-bugzilla@gcc.gnu.org
Fri Sep 22 08:00:00 GMT 2006


8.3.6/4 dcl.fct.default: "For non-template functions, default arguments can
be added in later declarations of a function in the same scope."
(there's a detailed example).

gcc 3.4.0 compiled the following code with no problem but release 4.1.1 rejects
it
(with or without the -ansi and -pedantic flags btw), with:

sjh@mill:~/c++$ g++ -ansi -pedantic x.c
x.c:5: error: default argument missing for parameter 2 of 'int f(int, int)'
x.c:5: error: default argument given for parameter 2 of 'int f(int, int)'
x.c:1: error: after previous specification in 'int f(int, int)'

sjh@mill:~/c++$ cat x.c
int f (int a, int b = 1)
{
   return a + b;
}
int f(int a = 6, int b); // can add default arguments  - 8.3.6/4 page 142
sjh@mill:~/c++$

sjh@mill:~/c++$ gcc -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: /home/sjh/gcc/gcc-4.1.1/configure
--prefix=/home/sjh/gcc/prefix/ --enable-languages=c,c++
Thread model: posix
gcc version 4.1.1
sjh@mill:~/c++$


-- 
           Summary: Wrongly rejects non-template function default arguments
                    in later declarations
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: greifel at megatop200 dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29177



More information about the Gcc-bugs mailing list