unused-variables

Disable one unused variable warning

混江龙づ霸主 提交于 2019-12-14 03:45:19
问题 How can I disable one warning in one place only? I have one variable which I temporarily don't use. Xcode shows me a warning about the "unused variable". I want to disable the warning, but for this variable only, not all warnings of this type. Is it possible without setting/getting this variable's value? 回答1: From GCC / Specifying Attributes of Variables (understood by Clang as well): int x __attribute__ ((unused)); or int y __attribute__((unused)) = initialValue ; 回答2: It's pretty simple:

Skip type check on unused parameters

天大地大妈咪最大 提交于 2019-12-09 05:29:42
问题 When I compile my typescript project, I'm using the noImplicitAny option so that I won't forget to specify the types on my variables and arguments. However sometimes you have arguments that you don't use. For example: jQuery.ajaxTransport("+*", function (options: JQueryAjaxSettings) { return { abort: function (_, callback: JQueryCallback) { I am not interested in the first argument of the abort function, so I ignore it by naming it _. Is that the proper way to do that in TypeScript? I couldn

Removing useless lines from c++ file

↘锁芯ラ 提交于 2019-12-04 05:26:50
There are many times when as I am debugging, or reusing some code, the file starts to acquire lines that don't do anything, though they may have done something at one point. Things like vectors and getting filled, and then go unused, classes/structs that are defined but never used, and functions that are declared, but never used. I understand that in many cases, some of these things are not superfluous, as they might be visible from other files, but in my case, there are no other files, just extraneous code in my file. While I understand that technically speaking, invoking push_back does

How to write a generic variadic lambda that discards its parameters?

我与影子孤独终老i 提交于 2019-12-04 03:22:44
问题 I want to write a lambda that takes an arbitrary number of arguments by universal reference and ignores them entirely. The obvious method would be to use the syntax for a variadic universal parameter pack and omit the parameter name: auto my_lambda = [](auto&&...) { return 42; }; This works fine (with gcc 4.9.2) until I try to pass a non trivially-copyable object: struct S { S() {} S(S const&) {} }; my_lambda("meow", 42, S{}); ^ error: cannot pass objects of non-trivially-copyable type

Why do underscore prefixed variables exist?

痞子三分冷 提交于 2019-12-04 02:53:19
问题 I am learning Rust, and came across the fact that adding an underscore at the beginning of a variable name will make the compiler not warn if it is unused. I am wondering why that feature exists, since unused variables are frowned upon. 回答1: I can see several reasons: You are calling a function that returns a #[must_use] type, but in your specific case, you know you can safely ignore the value. It is possible to use a _ pattern for that (which is not a variable binding, it's a pattern of its

Skip type check on unused parameters

本小妞迷上赌 提交于 2019-12-03 06:13:25
When I compile my typescript project, I'm using the noImplicitAny option so that I won't forget to specify the types on my variables and arguments. However sometimes you have arguments that you don't use. For example: jQuery.ajaxTransport("+*", function (options: JQueryAjaxSettings) { return { abort: function (_, callback: JQueryCallback) { I am not interested in the first argument of the abort function, so I ignore it by naming it _. Is that the proper way to do that in TypeScript? I couldn't find it in the guide. I suspect that it isn't the proper way, because I can only name one argument _.

use of variable in for loop not recognized in Golang

ⅰ亾dé卋堺 提交于 2019-12-02 03:37:40
问题 I'm developing in golang and I run the following for loop: // Define Initial Value i := 0 for { // Get Random data based on iteration data, i := GiveRandomData(i) // Save to database response, err := SaveToDatabase(data) if err != nil { log.Fatal(err) } fmt.Println(response) } However, when compiling this program, I get the following error: .\main.go:26: i declared and not used The Golang compiler doesn't seem to recognise that the i variable is given back to the function in the next loop.

use of variable in for loop not recognized in Golang

无人久伴 提交于 2019-12-02 01:23:44
I'm developing in golang and I run the following for loop: // Define Initial Value i := 0 for { // Get Random data based on iteration data, i := GiveRandomData(i) // Save to database response, err := SaveToDatabase(data) if err != nil { log.Fatal(err) } fmt.Println(response) } However, when compiling this program, I get the following error: .\main.go:26: i declared and not used The Golang compiler doesn't seem to recognise that the i variable is given back to the function in the next loop. Inside this function, the I variable changes value. What should I do to get rid of this compilation error

Why do underscore prefixed variables exist?

a 夏天 提交于 2019-12-01 16:20:59
I am learning Rust, and came across the fact that adding an underscore at the beginning of a variable name will make the compiler not warn if it is unused. I am wondering why that feature exists, since unused variables are frowned upon. I can see several reasons: Your are calling a function that returns a #[must_use] type, but in your specific case, you know you can safely ignore the value. It is possible to use a _ pattern for that (which is not a variable binding, it's a pattern of its own, but this is probably where the underscore prefix convention comes from), but you might want to

structured bindings and range-based-for; supress unused warning in gcc

我的未来我决定 提交于 2019-11-30 18:56:10
I want to traverse a map using structure bindings, ignoring the key: for (auto& [unused, val] : my_map) do_something(val); I have tried different options with gcc-7.2.0: // The warning is issued for ([[maybe_unused]] auto& [unused, val] : my_map) do_something(val); // Syntax error for (auto& [[[maybe_unused]] unused, val] : my_map) do_something(val); // The same two combinations above with [[gnu::unused]]. It seems that the [[maybe_unused]] attribute is not implemented yet for structure bindings. Is there any simple solution to this? Any macro, gcc/gnu extension, or any pragma to temporarily