monotone-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Monotone-devel] 'warning: unused parameter'


From: Václav Zeman
Subject: Re: [Monotone-devel] 'warning: unused parameter'
Date: Wed, 30 Apr 2014 11:19:59 +0200

On 30 April 2014 11:05, Stephen Leake wrote:
>
> Stephen Leake <address@hidden> writes:
>
> > Stephen Leake <address@hidden> writes:
> >
> >> The code that generates this is in simplestring_xform.hh:
> >>
> >> template<> inline
> >> origin::type get_made_from<std::string>(std::string const & thing)
> >> {
> >>   return origin::internal;
> >> }
> >>
> >> Is there a way to mark 'thing' as unused? or do we have to disable that
> >> warning with -Wno-unused-parameter?
> >
> > I found three answers on stack overflow:
> >
> > 1) comment out or delete the parameter name:
> >
> >     a) origin::type get_made_from<std::string>(std::string const & /* thing 
> > */)
> >
> >     b) origin::type get_made_from<std::string>(std::string const & )
> >
> > 2) cast it to void:
> >
> >     (void)thing;
> >
> > I prefer 1a; it most clearly documents that we know there is a parameter
> > by that name, but we are not using it in this case. Any objections?
>
> However, that is not appropriate in this case (command.hh):
>
> #define CMD_NO_WORKSPACE(C, name, aliases, parent, params, abstract, \
>                          desc, opts)                                 \
> namespace commands {                                                 \
>   class cmd_ ## C : public command                                   \
>   {                                                                  \
>   public:                                                            \
>     cmd_ ## C() : command(name, aliases, parent, false, false,       \
>                           params, abstract, desc, false,             \
>                           options::options_type() | opts, true)      \
>     {}                                                               \
>     virtual void exec(app_state & app,                               \
>                       command_id const & execid,                     \
>                       args_vector const & args) const;               \
>   };                                                                 \
>   cmd_ ## C C ## _cmd;                                               \
> }                                                                    \
> void commands::cmd_ ## C::exec(app_state & app,                      \
>                                command_id const & execid,            \
>                                args_vector const & args) const
>
>
> In most uses of CMD_NO_WORKSPACE, "execid" is not used, but it is used
> in some (cmd_netsync.cc clone).
>
> So we have to use (void)exec_id in the body of each case where it is not
> used.


You could special case GCC and introduce your own macro that expands
to the "unused" attribute in case of GCC:
http://gcc.gnu.org/onlinedocs/gcc-4.9.0/gcc/Function-Attributes.html#index-g_t_0040code_007bunused_007d-attribute_002e-3000

-- 
VZ



reply via email to

[Prev in Thread] Current Thread [Next in Thread]