c++/10608: default arguments not permitted, function typedef

nelsonbe@earthlink.net nelsonbe@earthlink.net
Sat May 3 04:03:00 GMT 2003


>Number:         10608
>Category:       c++
>Synopsis:       default arguments not permitted, function typedef
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Sat May 03 02:46:01 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     3.4 20030502 (experimental)
>Release:        unknown-1.0
>Organization:
>Environment:
GNU/Linux (Red Hat 7.3)
>Description:
------------------- default_args.cc -----------------------
#include <iostream>

int func(int val1, int val2 = 0)
{
        return val1 + val2;
}

int main()
{
        typedef int (*fptr)(int, int = 0);

        fptr fp = func;

        std::cout << fp(42) << '\n';
        std::cout << fp(42, 1) << '\n';
}
>How-To-Repeat:
- With g++ version 3.4 20030502 (experimental), compile as follows:

g++ default-args-func.cc

* This yields the following error diagnostic:
  error: default arguments are only permitted on functions

>Fix:
Using the same version of the compiler, the error is reduced to a warning when compiling the cited code as follows (adding -ansi and pedantic):

g++ -ansi -pedantic default-args-func.cc
>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-bugs mailing list