Boost logo

Boost :

Subject: Re: [boost] [function_types] Number of default parameters
From: Stephan T. Lavavej (stl_at_[hidden])
Date: 2011-02-08 21:28:02


[Lorenzo Caminiti]
> I'm confused because the following code doesn't compile on MSVC but it
> _does_ compiles fine on GCC...
> typedef void (func_type)(double num = -1.23); // NO STANDARD??
> 1) Is this a bug in GCC which should not accept `= -1.23` in `func_type`?

VC is correct to reject this code. (So does EDG.)

C++03 8.3.6 "Default arguments" [dcl.fct.default]/3: "A default argument expression shall be specified only in the parameter-declaration-clause of a function declaration or in a template-parameter (14.1). If it is specified in a parameter-declaration-clause, it shall not occur within a declarator or abstract-declarator of a parameter-declaration.88)"

Footnote 88: "This means that default arguments cannot appear, for example, in declarations of pointers to functions, references to functions, or typedef declarations."

> 2) Both, GCC and MSVC accept the parameter name `num` as part of the
> `func_type` type. Can parameter names be specified in function types?

Yes, that's totally fine, they're just ignored. C++03 8.3.5 "Functions" [dcl.fct]/8: "An identifier can optionally be provided as a parameter name", which applies to typedefs too.

Stephan T. Lavavej
Visual C++ Libraries Developer


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk