Take the 2-minute tour ×

I have defaulted my copy constructor and copy assignment operator as follows:

  Config(const Config& config) = default;
  Config& operator=(const Config& rhs) = default;

and then have given access to these via friendship to a free standing function. Upon creating a copy of a config object, I'm getting the following warning and note(?):

./cfg/config.hpp:129:3: warning: unused parameter 'config' [-Wunused-parameter] cfg/get.cpp: In function 'const cfg::Config& cfg::Get(bool)': cfg/get.cpp:34:30: note: synthesized method 'cfg::Config::Config(const cfg::Config&)' first required here

It would appear the copy constructor isn't even being instantiated. Despite this, the code seems to run.

gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)

share|improve this question
Works fine on g++ by the way. May be compiler issue. –  iammilind Oct 9 '12 at 5:58
You mention an error in the title, but here you only show a warning. –  juanchopanza Oct 9 '12 at 6:05
Sorry about that, i also had error in my question initially too before correcting, forgot to correct title! –  Troy Oct 9 '12 at 6:33

2 Answers 2

up vote 7 down vote accepted

Just omit the parameters:

Config(const Config&) = default;
Config& operator=(const Config&) = default;

The statements above instruct the compiler to generate default special member functions of the type stated, but the details of these implementations are not specified. The parameter names are redundant and have no effect. The compiler is free to issue warnings for legal code.

From §8.4.2:

... A function that is explicitly defaulted shall

— be a special member function,

— have the same declared function type (except for possibly differing ref-qualifiers and except that in the case of a copy constructor or copy assignment operator, the parameter type may be “reference to non-const T”, where T is the name of the member function’s class) as if it had been implicitly declared ...

share|improve this answer
Any specific reason why? what happens if I provide parameter names? –  Naveen Oct 9 '12 at 5:47
I think compiler said enough here: warning: unused parameter 'config' –  Denis Ermolin Oct 9 '12 at 5:57
@Naveen XXXX = default is just an instruction to the compiler to generate the special member matching a certain function type. The details of the actual implementation aren't specified. The parameter here has no effect. –  juanchopanza Oct 9 '12 at 5:59
It was more the note: that I was concerned about, but it seems that the 2 are related. Synthesised method xxx first required here doesn't seem to have any relation to an unused variable warning. Sigh. Thanks! –  Troy Oct 9 '12 at 6:35
@juanchopanza -- one reason to not omit the parameter names is for documentation reasons. Some documentation generators (notably doxygen) expect to see the same name in the docs and the param list; omitting it from the param list causes warnings there. –  AnthonyFoiani May 15 '13 at 5:54

I just ran into this today; while I'm just using the "omit the names" workaround, there are two relevant bugs open against GCC:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50895 -- a suggestion to omit the "unused parameter" warning on virtual methods (or maybe just empty virtual methods).

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57211 -- this problem (unused param names on defaulted methods), complicated by the fact that the line/column error indicator points at the top of the class defn, instead of at the defaulted method defn.

As can be seen in my comments to the bugs, my interest is in making my documentation more consistent. Ideally I could have my code and my docs both build without warnings.

If nothing else, the warning here is IMHO incorrect: the parameter is certainly used, it's just used by a different name or through some other mechanism.

share|improve this answer

Your Answer


