Questions tagged [unused-variables]

Use this tag when question related to unused variables issues as warnings

179 questions
4
votes
2 answers

Nested pattern matching in Ocaml

I want to write a function in Ocaml that given a list of quadruples and a quadruple (x,y,z,f), returns a list of that contains the tuples (x',y',z',g) such that x = x' or y=y' or z = z' (these are integers). Here is my first attempt let rec…
Amin
  • 251
  • 2
  • 15
4
votes
3 answers

Should compilers ignore unused variables that result in constructors or destructors being run?

I have some code that I put in a destructor to ensure it is run both on normal exit and exception stack unwinding: struct withProtectedClose { ~withProtectedClose() { // Do some cleanup here... } }; void test() { withProtectedClose…
WilliamKF
  • 41,123
  • 68
  • 193
  • 295
3
votes
1 answer

Lisp - allow variable to be used *or* unused?

If I (declare (ignore foo)) then lisp* won't warn me about unused variables, but will warn if I do use the variable. Is there a way I can turn off warnings either way? Asking because I want to write some macros that introduce common/standard…
3
votes
2 answers

for-loop counter gives an unused-variable warning

My program has an iterative algorithm with a for-loop that I had written as for ( auto i: std::views::iota( 0u, max_iter ) ) { ... } I really like the fact that it can be written like this, even if the necessary header files are enormous. When I…
alle_meije
  • 2,424
  • 1
  • 19
  • 40
3
votes
1 answer

Is [[nodiscard]] any different from [[gnu::warn_unused_result]]?

I had some code that used the GCC extension [[gnu::warn_unused_result]] (a.k.a. __attribute__((__warn_unused_result__))). Now I attempted to use C2x's [[nodiscard]] and I got an incomprehensible error. I'm not sure if the usage of [[nodiscard]] is…
3
votes
1 answer

What is the functional difference between "(void) cast" vs. "__attributes__" for silencing unused argument warnings?

Is there any functional difference between marking a virtual method's unused parameter arguments with GCC's __attribute__((unused)) and casting the argument to (void)? class Other { virtual int sum(int a, int b, int c); }; class Example : Other…
ktb
  • 1,498
  • 10
  • 27
3
votes
3 answers

Can an unused function instantiate a variable template with side-effects according to C++14?

Here is my code: #include class MyBaseClass { public: static int StaticInt; }; int MyBaseClass::StaticInt = 0; template class MyClassT : public MyBaseClass { public: MyClassT() { StaticInt = N; …
Jack White
  • 896
  • 5
  • 7
3
votes
1 answer

Incremented variable "never used"?

I'm kind of inexperienced with C++, and I'm converting a program that I wrote in C to C++. I have a RollDice function that takes numbers that I read in from a text file and uses them to generate the number. This is the function in C: void…
3
votes
2 answers

How to avoid "unused variable in a for loop" error

How to avoid "unused variable in a for loop" error with code like ticker := time.NewTicker(time.Millisecond * 500) go func() { for t := range ticker.C { fmt.Println("Tick at", t) } }() if I actually don't use the t variable?
Bruce
  • 181
  • 4
  • 11
3
votes
3 answers

How to use UNUSED macro to silence warning within a CONSTEXPR function?

I'm experiencing an issue where a static member function uses an UNUSED macro to silence compiler warnings. When the macro is in effect, it causes GCC and Clang to reject the function as a constexpr. Here's the test case: $ cat test.cxx #include…
jww
  • 97,681
  • 90
  • 411
  • 885
3
votes
1 answer

how to declare ellipsis defined va_list unused

I am dealing with the log macros that are defined something like: #define LOGD(...) rtt_printf(TERMINAL_DEBUG, ##__VA_ARGS__) #define LOGV(...) rtt_printf(TERMINAL_NORMAL, ##__VA_ARGS__) It is all good, but I would like to disable…
arapEST
  • 491
  • 1
  • 4
  • 16
3
votes
2 answers

How to make OCaml compiler report unused functions?

I wonder if is there any ways to make OCaml compiler report warnings about unused functions? I googled but there are not much topics discussed about this feature. In particular, in the following program, there are two functions "foo" and "bar"…
Trung Ta
  • 1,582
  • 1
  • 16
  • 25
3
votes
1 answer

JSLint No dynamic change of Unused Parameters

I have looked at many stackoverflow answers about getting rid of (necessary) unused parameters errors from jslint by locally wrapping functions as follows: /*jslint unparam: true*/ //my function with unused parameters /*jslint unparam:…
3
votes
1 answer

Strange behavior of -Wunused-value warning

I just spent some time finding out why a mutable set didn't correctly intersect itself with another set, using [someMutableSet intersectsSet:anotherSet]; // not the best idea Of course, the correct syntax is [someMutableSet…
ilya n.
  • 18,398
  • 15
  • 71
  • 89
3
votes
1 answer

Too many CSRF tokens generated (PHP), how do I deal with them?

I run into a problem. Following OWASP cheatsheet, I implemented a one-time-use CSRF token system in PHP (basically copy&paste from OWASP). Each form or link (link that generate some action) will create its own CSRF token, once it's used, it will be…
CONEJO
  • 388
  • 1
  • 11