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
Created attachment 11820 [details] "Broken" preprocessed source.
Created attachment 11821 [details] "Working" preprocessed source.
Apologies for inlining preprocessor output. I have attached the files.
Your workaround is really invalid code and should be rejected. So what we have here is an accepts invalid that is not a regression.
Agreed. Wasn't sure if it was actually supposed to work or not.
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.
Fixed for 4.9.0.