Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce warnings by using variables to debug_print(..) #331

Closed
lifflander opened this issue Mar 27, 2019 · 2 comments
Closed

Reduce warnings by using variables to debug_print(..) #331

lifflander opened this issue Mar 27, 2019 · 2 comments
Assignees

Comments

@lifflander
Copy link
Collaborator

This is related to #329: enabling all warning by default. The debug_print macro, when disabled, does not "use" the variables passed to it from a static compiler analysis perspective. This causes spurious warnings about unused variables that are used in a debug configuration.

Modify debug_print to always use its arguments, even when its disabled.

There are two possible solutions:

  1. Re-write the debug_print macro to recursively use the variables doing something like this. While this approach works (void)(a) recursively accessing each variable in the macro will be expensive from a cpp perspective.
 #define use_it(a) (void)(a);
  1. Use a C++ parameter pack to recursively use the args.
    template <typename... Args>
    struct A;
    
    template <typename T, typename... Args>
    struct A<T, Args...> {
      static void forceUseArgs(T&& tp, Args&&... args) {
    	(void)(tp);
    	A::forceUseArgs<Args>(std::forward<Args>(args)...);
      }
    };
    
    template <>
    struct A<> {
      static void forceUseArgs() {  }
    };

@nlslatt @PhilMiller

@lifflander lifflander self-assigned this Mar 27, 2019
@lifflander
Copy link
Collaborator Author

lifflander commented Mar 27, 2019

I have an implementation now. I have tested (with multiple compilers and versions) that it does not output any code when optimization is turned on. Take a look:

https://godbolt.org/z/ZbGpNL

@lifflander
Copy link
Collaborator Author

Merged, closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant