compiler-warnings

Wrong compiler warning when comparing struct to null

谁说胖子不能爱 提交于 2019-11-30 18:12:24
Consider the following code: DateTime t = DateTime.Today; bool isGreater = t > null; With Visual Studio 2010 (C# 4, .NET 4.0), I get the following warning: warning CS0458: The result of the expression is always 'null' of type 'bool?' This is incorrect; the result is always false (of type bool ): Now, the struct DateTime overloads the > (greater than) operator. Any non-nullable struct (like DateTime) is implicitly convertible to the corresponding Nullable<> type. The above expression is exactly equivalent to bool isGreater = (DateTime?)t > (DateTime?)null; which also generates the same wrong

gcc options: warning on non-void functions without a return statement

佐手、 提交于 2019-11-30 17:11:10
问题 Does anyone know a gcc/g++ option that generates an error/warning if there's a function that has a non-void return value but doesn't contain a return statement in its definition? e.g.: int add(int a, int b) { a+b; } Many thanks in advance! 回答1: -Wreturn-type. It's enabled by -Wall (which you should always be running with, along with -Werror -Wextra ). 来源: https://stackoverflow.com/questions/9924570/gcc-options-warning-on-non-void-functions-without-a-return-statement

Does anyone know of a way to view all compiler warnings for a VB.NET project?

最后都变了- 提交于 2019-11-30 15:07:41
问题 VB.NET has this rather annoying limitation which caps compiler warnings reported at 100. vbc : warning BC42206: Maximum number of warnings has been exceeded. This makes things rather frustrating when trying to size up the amount of effort that would be required to comply with VB.NET best practices, such as enabling Option Strict. Is there any way where this limitation could either be removed, adjusted, or could warnings be gathered by some other means (such as through a 3rd party code

How to overcome pointless C++ compiler warnings elegantly?

吃可爱长大的小学妹 提交于 2019-11-30 14:31:07
问题 This question is not bound to any specific compiler warning, the following is just an example. Currently when I want a loop that checks an exit condition inside: while( true ) { doSomething(); if( condition() ) { break; } doSomethingElse(); } I can't just write that in Visual C++ - it will emit a C4127 conditional expression is constant warning. The compiler will wave it in my face although it's quite obvious that while(true) can't have been written accidentially. Suppose I want code that

Conditionally disable warnings with qmake/gcc?

南楼画角 提交于 2019-11-30 14:21:32
I am involved with a software project written in Qt and built with qmake and gcc on Linux. We have to link to a third-party library that is of fairly low quality and spews tons of warnings. I would like to use -W -Wall on our source code, but pass -w to the nasty third-party library to keep the console free of noise and clutter so we can focus on our code quality. In qmake, is there a way to conditionally add CFLAGS/CXXFLAGS to certain files and libraries? Jonathan, I think the problem is where your source files are including header files from 3rd party libraries, and you want to switch off

Unchecked Cast Warning when calling 'Class.forName'

两盒软妹~` 提交于 2019-11-30 14:05:14
My code is as follows package com.foo; public class TestComposition { public static void main(String[] args) { try { Class<Foo> fooClass = (Class<Foo>) Class.forName("Foo"); } catch (ClassNotFoundException e) { e.printStackTrace(); } } } The assignment within the 'try' block results in a warning stating Type safety: Unchecked cast from Class<capture#1-of ?> to Class<Foo> Why is this? Well, to start with let's be clear where the problem is - it's in the cast itself. Here's a shorter example: public class Test { public static void main(String[] args) throws Exception { Object x = (Class<Test>)

Does anyone know of a way to view all compiler warnings for a VB.NET project?

与世无争的帅哥 提交于 2019-11-30 13:41:28
VB.NET has this rather annoying limitation which caps compiler warnings reported at 100. vbc : warning BC42206: Maximum number of warnings has been exceeded. This makes things rather frustrating when trying to size up the amount of effort that would be required to comply with VB.NET best practices, such as enabling Option Strict. Is there any way where this limitation could either be removed, adjusted, or could warnings be gathered by some other means (such as through a 3rd party code-analysis tool)? Mark Hurd As of VB11, in VS2012, vbc no longer has a maximum error limit when called from the

unchecked call to ArrayAdapter

江枫思渺然 提交于 2019-11-30 13:35:32
问题 I get the following warning when I instantiate my ArrayAdapter (compiles fine): warning: [unchecked] unchecked call to ArrayAdapter(android.content.Context,int,java.util.List<T>) as a member of the raw type android.widget.ArrayAdapter ArrayAdapter spinnerArrayAdapter = new ArrayAdapter(CFAMain.this, android.R.layout.simple_spinner_dropdown_item, spinnerArray); And here's the problem line: ArrayAdapter spinnerArrayAdapter = new ArrayAdapter(CFAMain.this, android.R.layout.simple_spinner

“Delegate subtraction has unpredictable result” in ReSharper/C#?

孤者浪人 提交于 2019-11-30 13:33:32
问题 When using myDelegate -= eventHandler ReSharper (version 6) issues: Delegate subtraction has unpredictable result The rational behind this is explained by JetBrains here. The explanation makes sense and, after reading it, I'm doubting all my uses of - on delegates. How then , can I write a non-auto event without making ReSharper grumpy? or, is there a better and/or "correct" way to implement this? or, can I just ignore ReSharper? Here is simplified code: public delegate void MyHandler (object

Visual Studio 2015 - Compiler Warning (level 2) C4146

家住魔仙堡 提交于 2019-11-30 13:21:35
I have the following line in my code signed int test_case= -2147483648; which generates the error: C4146 unary minus operator applied to unsigned type, result still unsigned but this is still with the data range of teh signed integer type: __int32 signed, signed int, int –2,147,483,648 to 2,147,483,647 The strange things is assigning it as signed long gives this same error, i.e. signed long test_case= -2147483648; The changes below compile OK: signed int test_case= -2147483647; signed int test_case= 2147483649; signed long test_case= -214748364800; Has anyone seen this issue with Visual Studio