[Bug c++/18670] New: g++ is allowing defaulted parameters in function definition in a weird way

imran at esscc dot uq dot edu dot au gcc-bugzilla@gcc.gnu.org
Thu Nov 25 04:54:00 GMT 2004


First of all let me mention the fact that I do NOT have a copy of the standards
document with me. There, now that its out of the way; here goes...

My understanding is that the trailing N parameters can be defaulted. the
following code shows how some trailing params are defaulted in the function
declaration; but more of them are defaulted in the definition!

// start program
//#include <iostream>

void f( int i, int j=0 );
void blah( void );

int main( void )
{
    f( 4, 5 ); // if this is f() the program won't compile
    blah();
    return 0;
}

void f( int i=0, int j )
{
    // std::cout << "i -> " << i << " j -> " << j << std::endl;
}

void blah( void )
{
    f();
}

// end program

The above simple program illustrates what I have mentioned earlier. The code
compiles fine with this cmdline:

g++ func.cpp -o func

Some people have reported that it compiles and runs fine with gcc 3.4.x as well.
 Although rare, it is possible to observe such code huge projects. If its within
the standards, please ignore.

-- Imran

ps: where do i attach the stuff generated by 'gcc -v -save-temps
all-your-options source-file' as mentioned in the 'how to post bugs in gcc'
document?

-- 
           Summary: g++ is allowing defaulted parameters in function
                    definition in a weird way
           Product: gcc
           Version: 3.3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: imran at esscc dot uq dot edu dot au
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: 3.3.2
  GCC host triplet: 3.3.2
GCC target triplet: 3.3.2


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



More information about the Gcc-bugs mailing list