Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • tnl-dev tnl-dev
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 36
    • Issues 36
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 4
    • Merge requests 4
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • Repository
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • TNL
  • tnl-devtnl-dev
  • Issues
  • #80

Closed
Open
Created Jul 11, 2020 by Tomáš Jakubec@jakubecDeveloper

Silence of unused variable warning

It would be nice to silence the warnings caused by unused variables. There are several ways to do it:

  1. do not name the unused argument (not preferable),
  2. use [[maybe_unused]] (since C++17) in function definition,
  3. typecast the unused variable (void) var. This approach is used in Qt. For example consider the following function:
   static std::string name( CudaStatusType error_code )
   {
#ifdef HAVE_CUDA
      return cudaGetErrorName( error_code );
#else
    (void) error_code;
      throw CudaSupportMissing();
#endif
   }

The approach in Qt discussed here is the following:

#define UNUSED(var) (void) var

Then, the warning can be silenced by UNUSED(error_code);.

Assignee
Assign to
Time tracking