Description:

  g++ appears to have issues when declaring function pointer types that accept
default function parameters. However it does not have issues when declaring
non-pointer function types that accept default function parameters. For
example, the following code:

  typedef void (* funcptr) (int = 10);

  Produces the error "default arguments are only permitted for function
parameters". However, a "workaround" for this exists. The following code
compiles without problems, and the default parameter works:

  typedef void (funcptrhack) (int = 10);
  typedef funcptrhack * funcptr;

  I believe this is a bug because a workaround exists, and because of the
inconsistency. Additionally, this problem does not seem to occur on pre-3.4.2
versions of GCC (the next lowest version tested was 3.3.3; not sure where in
that range it started failing). However, I am not sure what the bug is: I
believe that either both of the above examples should succeed or both should
fail.

"Buggy" behavior observed on versions:
  3.4.2 [g++.exe (GCC) 3.4.2 (mingw-special)]
  3.4.3 [specific version unavailable]
  3.4.4 [specific version unavailable]
  3.4.4 [g++ (GCC) 3.4.4 (cygming special) (gdc 0.12, using dmd 0.125)]
  3.4.5 [g++ (GCC) 3.4.5 (Gentoo 3.4.5, ssp-3.4.5-1.0, pie-8.7.9)]
  4.0.3 [Ubuntu 4.0.3-1ubuntu5]

"Working" behavior observed on versions:
  3.2   [g++ (GCC) 3.2 20020903 (Red Hat Linux 8.0 3.2-7)]
  3.2.2 [specific version unavailable]
  3.3.3 [specific version unavailable]

Configuration options unavailable. Some system types and GCC versions
unavailable as indicated above.

Preprocessed output for both cases follows:

---

"Buggy" output, compiled with:

  g++ -W -Wall -pedantic

Preprocessed file:

# 1 "gccbug.cpp"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "gccbug.cpp"

typedef void (* funcptr) (int = 10);

void testfunc (int) {
}

int main (int, char **) {

  funcptr fp = &testfunc;

  (*fp)();
  (*fp)(20);

  return 0;

}

---

"Working" output, compiled with:

  g++ -W -Wall -pedantic

Preprocessed file:

# 1 "gccbug.cpp"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "gccbug.cpp"

typedef void (funcptrhack) (int = 10);
typedef funcptrhack * funcptr;

void testfunc (int) {
}

int main (int, char **) {

  funcptr fp = &testfunc;

  (*fp)();
  (*fp)(20);

  return 0;

}

---

-Jason


-- 
           Summary: Inconsistent "default arguments are only permitted for
                    function parameters".
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jason dot cipriani at gmail dot com
 GCC build triplet: Multiple, see report.
  GCC host triplet: Multiple, see report.
GCC target triplet: Multiple, see report.


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

Reply via email to