unused-variables

Getting MatchError when using a placeholder for an unused variable

泪湿孤枕 提交于 2021-01-23 04:49:37
问题 With Scala 2.13.x, I am getting scala.MatchError: null when I use a placeholder for an unused variable: scala> object Test { | val _: Any = null | } object Test scala> Test scala.MatchError: null ... 41 elided But with Scala 2.12.x, I am not getting scala.MatchError: null : scala> object Test { | val _: Any = null | } defined object Test scala> Test res1: Test.type = Test$@784c5ef5 Any reason? 回答1: As stated in scala 2.13 release notes: Underscore is no longer a legal identifier unless

“Variable is never assigned” warning in IntelliJ IDEA can be suppressed only “partially”

久未见 提交于 2020-06-09 15:51:26
问题 Java EE + IntelliJ Idea 2016.3: I've written a class and declared a private field with a @Inject annotation. I have successfully got rid of the "unused declaration" notification from the "inspection results" window by adding javax.inject.Inject to settings -> editor -> inspections -> Java -> declaration redundancy -> unused declarations -> entry points -> annotations -> mark field as implicitly written when annotated by (based on this post). Unfortunately the field is still underlined and a

How to make OCaml compiler report unused functions?

走远了吗. 提交于 2020-05-30 04:26:20
问题 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" which are declared but "bar" is not used in the "_" function. So I think that the OCaml compiler should report "bar" as an unused function. let foo x y = x + y let bar x y z = x + y + z (* should be reported unused *) let _ = let x = foo 1 2 in x 回答1:

How to make OCaml compiler report unused functions?

人走茶凉 提交于 2020-05-30 04:25:49
问题 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" which are declared but "bar" is not used in the "_" function. So I think that the OCaml compiler should report "bar" as an unused function. let foo x y = x + y let bar x y z = x + y + z (* should be reported unused *) let _ = let x = foo 1 2 in x 回答1:

Removing useless lines from c++ file

若如初见. 提交于 2020-01-01 09:18:48
问题 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

Why “unused attribute” generated warning for array of struct?

佐手、 提交于 2019-12-30 11:16:31
问题 Here used, unused attribute with structure. According to GCC document: unused : This attribute, attached to a variable, means that the variable is meant to be possibly unused. GCC will not produce a warning for this variable. But, In the following code, array of struct generated warning. #include <stdio.h> struct __attribute__ ((unused)) St { int x; }; void func1() { struct St s; // no warning, ok } void func2() { struct St s[1]; // Why warning??? } int main() { func1(); func2(); return 0; }

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

眉间皱痕 提交于 2019-12-30 06:12:53
问题 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

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

回眸只為那壹抹淺笑 提交于 2019-12-30 06:12:32
问题 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

Unused parameter in c++11

混江龙づ霸主 提交于 2019-12-18 10:10:33
问题 In c++03 and earlier to disable compiler warning about unused parameter I usually use such code: #define UNUSED(expr) do { (void)(expr); } while (0) For example int main(int argc, char *argv[]) { UNUSED(argc); UNUSED(argv); return 0; } But macros are not best practice for c++, so. Does any better solution appear with c++11 standard? I mean can I get rid of macros? Thanks for all! 回答1: I have used a function with an empty body for that purpose: template <typename T> void ignore(T &&) { } void

Why the compiler does not issue a warning when an object std::vector is declared but never used? [duplicate]

人盡茶涼 提交于 2019-12-18 03:55:23
问题 This question already has answers here : A variable not detected as not used (3 answers) Closed 3 years ago . #include <vector> class Object { }; int main() { Object myObject; std::vector<int> myVector; } Compiler emits: warning: unused variable 'myObject' [-Wunused-variable] No warning for myVector . Why? Is there any way to enable this? 回答1: Whether declaring (and thus initialising and at some point destructung) an arbitrary object has visible side effects cannot be determined in general.