You are not logged in.

#1 2016-05-13 17:00:32

snack
Member
From: Italy
Registered: 2009-01-13
Posts: 861

Unused variables and Doxygen

GCC 6 is very verbose in reporting unused variables, which I find good. However, this poses some problems when using Doxygen. For example, I have this definition inside one of my headers:

/*! @brief Initialization method.
 *
 * Implementations of this method can create data branches in #tree. Histograms and graphs can also
 * be initialized here. The number of the current processing pass can also be specified to
 * allow different configurations for different passes.
 *
 * @param tree The ROOT tree where branches can be created.
 * @param pass The number of the current pass (0 = first pass, 1 = second pass etc.)
 * @return true if the initialization procedure has been successful, false otherwise.
 */
virtual bool Initialize(TTree *tree, int pass = 0) {
  return true;
}

This is a default void implementation for a mother class which is eventually overridden by children. GCC gives warnings about tree and pass being unused; if I remove the variable names so that GCC is happy then Doxygen gets angry:

/home/mori/DQM/Core/include/DQProcessor.h:52: warning: argument 'tree' of command @param is not found in the argument list of DQM::DQProcessor::Initialize(TTree *, int=0)
/home/mori/DQM/Core/include/DQProcessor.h:52: warning: argument 'pass' of command @param is not found in the argument list of DQM::DQProcessor::Initialize(TTree *, int=0)

Is there a way, without silencing GCC's warning about unused variables, to solve this issue? Thanks.

Offline

#2 2016-05-13 17:26:07

eschwartz
Fellow
Registered: 2014-08-08
Posts: 4,097

Re: Unused variables and Doxygen

Use a diagnostic pragma?


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

#3 2016-05-13 17:28:30

snack
Member
From: Italy
Registered: 2009-01-13
Posts: 861

Re: Unused variables and Doxygen

Ehm... can you elaborate a bit, Eschwartz? I'm a Doxygen noob and I'm still learning how to use it. Thanks!

Offline

#4 2016-05-13 17:31:00

Steef435
Member
Registered: 2013-08-29
Posts: 577
Website

Re: Unused variables and Doxygen

I find it weird that you get warnings about this, I can't remember warnings about unused parameters from back when I fiddled with C++.

Is there a reason why you're implementing the virtual function? If the function is eventually going to overridden, why not make it a pure virtual function? Sounds like you're working on an abstract base class to me.

Offline

#5 2016-05-13 17:31:10

eschwartz
Fellow
Registered: 2014-08-08
Posts: 4,097

Re: Unused variables and Doxygen


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

#6 2016-05-13 17:33:46

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: Unused variables and Doxygen

Web search also gives suggestions like http://stackoverflow.com/questions/3599 … -in-c-code

With C++17 you get an attribute in the language standard:

virtual bool Initialize([[maybe_unused]] TTree *tree, [[maybe_unused]] int pass = 0) {

Offline

#7 2016-05-13 17:44:58

snack
Member
From: Italy
Registered: 2009-01-13
Posts: 861

Re: Unused variables and Doxygen

It seems there's plenty of solutions, portable and not. I'll give a look and try to find the best suited for me. Thanks to everybody.

Offline

#8 2016-05-15 12:26:27

The Infinity
Member
Registered: 2014-07-05
Posts: 91
Website

Re: Unused variables and Doxygen

I usually just define something like

#define VAR_UNUSED(x) (void)x;

and use it like this

virtual bool Initialize(TTree *tree, int pass = 0) {
  VAR_UNUSED(tree)
  VAR_UNUSED(pass)
  return true;
}

Tested it with GCC, Clang, mingw-w64.

Offline

Board footer

Powered by FluxBB