Bug 28262 - Inconsistent "default arguments are only permitted for function parameters".
Summary: Inconsistent "default arguments are only permitted for function parameters".
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: unknown
: P3 minor
Target Milestone: 4.9.0
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
Depends on:
Blocks:
 
Reported: 2006-07-05 00:20 UTC by Jason Cipriani
Modified: 2013-07-06 08:55 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 4.9.0
Known to fail: 2.95.3, 3.0.4, 3.2.3, 3.3.3, 3.4.0, 4.0.0, 4.1.0, 4.2.0
Last reconfirmed: 2006-07-05 00:31:16


Attachments
"Broken" preprocessed source. (163 bytes, text/plain)
2006-07-05 00:22 UTC, Jason Cipriani
Details
"Working" preprocessed source. (175 bytes, text/plain)
2006-07-05 00:22 UTC, Jason Cipriani
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jason Cipriani 2006-07-05 00:20:43 UTC
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
Comment 1 Jason Cipriani 2006-07-05 00:22:26 UTC
Created attachment 11820 [details]
"Broken" preprocessed source.
Comment 2 Jason Cipriani 2006-07-05 00:22:44 UTC
Created attachment 11821 [details]
"Working" preprocessed source.
Comment 3 Jason Cipriani 2006-07-05 00:23:55 UTC
Apologies for inlining preprocessor output. I have attached the files.
Comment 4 Andrew Pinski 2006-07-05 00:31:16 UTC
Your workaround is really invalid code and should be rejected.
So what we have here is an accepts invalid that is not a regression.
Comment 5 Jason Cipriani 2006-07-05 00:35:10 UTC
Agreed. Wasn't sure if it was actually supposed to work or not.
Comment 6 Andrew Pinski 2006-07-05 00:41:06 UTC
Just a note, the follow patch deprecated them in 3.4:
http://gcc.gnu.org/ml/gcc-patches/2003-07/msg02485.html

Though it seems to miss this part for some reason.
Comment 7 Paolo Carlini 2013-07-06 08:55:56 UTC
Fixed for 4.9.0.