compiler-warnings

Suppress “discarded non-Unit value” warning

风格不统一 提交于 2019-11-28 02:43:07
问题 I have added the scalac command line argument -Ywarn-value-discard to my build because this would have caught a subtle bug that I just found in my code. However, I now get some warnings for "discarded non-Unit value" that are about intentional discards, not bugs. How do I suppress those warnings? 回答1: You suppress these warning by explictly returning unit (that is () ). By example turn this: def method1() = { println("Hello") "Bye" } def method2() { method1() // Returns "Bye", which is

why am I not getting an “used uninitialized” warning from gcc in this trivial example? [duplicate]

懵懂的女人 提交于 2019-11-28 01:49:42
This question already has an answer here: Why is there not any warning on a declaration without initialization in a for loop? 1 answer Once again a stupid uninitialized variable error in How to fix this segmentation error in a sequence inverting program? . So I was going to repeat the "please use -Wall flags" comment, but when I tested the code against warnings, I found no warnings reported to my great surprise. So I trimmed it down to this below (this code makes no sense for execution purposes but it illustrates what I want to show): #include <stdio.h> int main() { int i,len=12; /* printf("%d

Compile time warning when using 'Microsoft.Office.Interop.Word._Document.Close'

隐身守侯 提交于 2019-11-28 00:41:44
Anyone know how to solve this warning message? Ambiguity between method 'Microsoft.Office.Interop.Word._Document.Close(ref object, ref object, ref object)' and non-method 'Microsoft.Office.Interop.Word.DocumentEvents2_Event.Close'. Using method group. Tod The only way I've managed to resolve the warning is to use an explicit cast: var doc_close = (Microsoft.Office.Interop.Word._Document) _doc; doc_close.Close(); If you already have a using for Microsoft.Office.Interop.Word you can simplify the cast to: var doc_close = (_Document) _doc; doc_close.Close(); or even just ((_Document)_doc).Close();

warning: return type defaults to ‘int’ [-Wreturn-type]

五迷三道 提交于 2019-11-27 23:33:54
I'm a Linux user who started learning C and I'm trying to compile this source that I typed: #include <stdio.h> main() { float c,d; c = 10215.3; d = c / 3; printf("%3.2f\n",d); return 0; } It compiled with this using a makefile that I wrote: cc -Wall -g printf.c -o printf but I'm getting this warning: printf.c:2:1: warning: return type defaults to ‘int’ [-Wreturn-type] it compiles the code and I get the desired output but I want to understand what this means main() should be int main() In C89, the default return type is assumed to be int , that's why it works. In C89, the default return type is

Globally suppress c# compiler warnings

烈酒焚心 提交于 2019-11-27 23:28:38
In my app I have a fair number of entities which have fields which are getting their values set via reflection. (In this case NHibernate is setting them). I'd like to get rid of the "x is never assigned to and will always have its default value 0" warnings, so I can more easily pick out the other warnings. I realize you can surround them in pragma directives, but AFAIK you have to do this for each one. Is there a project wide or solution wide way I could do this? Use the C# commandline option /nowarn http://msdn.microsoft.com/en-us/library/7f28x9z3(VS.80).aspx To do this within visual studio

In C++, when can two variables of the same name be visible in the same scope?

会有一股神秘感。 提交于 2019-11-27 23:13:16
This code illustrates something that I think should be treated as bad practice, and elicit warnings from a compiler about redefining or masking a variable: #include <iostream> int *a; int* f() { int *a = new int; return a; } int main() { std::cout << a << std::endl << f() << std::endl; return 0; } Its output (compiled with g++): 0 0x602010 I've looked at a couple references (Stroustrup and The Complete C++ Reference) and can't find anything about when and why this is allowed. I know that it's not within a single local scope, though. When and why is this allowed? Is there a good use for this

Turn off Xcode's unused variable warnings while typing

流过昼夜 提交于 2019-11-27 23:04:31
问题 I'm sick to death of Xcode's prolific use of live "unused variable" warnings while I am typing. I keep thinking I have an error in my syntax, stop what I'm doing, check the warning, only to see it's an unused variable warning. Of course it's unused, I just typed it! I don't mind the compile-time unused variable warnings, those are very useful, but I hate the live warnings as I'm typing code. Is there any way I can turn off this warning completely everywhere, either app-wide or for an entire

Why didn't the compiler warn me about an empty if-statement?

醉酒当歌 提交于 2019-11-27 22:59:53
问题 I'm using Keil uVision v4.74 and have enabled the option "All Warnings". I wrote the following intentional code: if(condition matched) { //do something } When I rebuilt my project, I got 0 errors, 0 warnings. However, when I accidentally wrote: if(condition matched); { //do something } I also got 0 errors, 0 warnings. It was next to impossible for me to find out that a small ; following the if condition was the root of the problem. Why didn't the compiler treat it as a warning and inform me?

The parameter 'foo' should not be assigned — what's the harm?

早过忘川 提交于 2019-11-27 22:57:52
问题 Compare this method: void doStuff(String val) { if (val == null) { val = DEFAULT_VALUE; } // lots of complex processing on val } ... to this method: void doStuff(String origVal) { String val = origVal; if (val == null) { val = DEFAULT_VALUE; } // lots of complex processing on val } For the former method, Eclipse emits the warning "The parameter 'val' should not be assigned". Why? To my eye, the former is cleaner. For one thing, it doesn't force me to come up with two good names for val

How to eliminate warning about ambiguity?

我怕爱的太早我们不能终老 提交于 2019-11-27 22:38:46
I have this warning: Warning 3 Ambiguity between method 'Microsoft.Office.Interop.Word._Application.Quit(ref object, ref object, ref object)' and non-method 'Microsoft.Office.Interop.Word.ApplicationEvents4_Event.Quit'. Using method group. on my line wordApplication.Quit(); I have tried replacing it with: wordApplication.Quit(false); // don't save changes and wordApplication.Quit(false, null, null); // no save, no format but it keeps giving me this warning. It's not a huge problem because the code compiles perfectly and functions as expected, but I'd like to get rid of the warnings. What can I