FAQ Database Discussion Community


Generating warnings for Int32 to Int64 casts

c#,casting,compiler-warnings,static-analysis
Is there a way to generate compile time warnings for implicit int to long conversions? (An answer that involves a static analysis tool such as FxCop would be fine.) Casting an int to a long is obviously a safe operation, but say we have a library that used to have...

Why does GCC emit a warning when using trigraphs, but not when using digraphs?

c,gcc,compiler-warnings,digraphs,trigraphs
Code: #include <stdio.h> int main(void) { ??< puts("Hello Folks!"); ??> } The above program, when compiled with GCC 4.8.1 with -Wall and -std=c11, gives the following warning: source_file.c: In function ‘main’: source_file.c:8:5: warning: trigraph ??< converted to { [-Wtrigraphs] ??< puts("Hello Folks!"); ??> ^ source_file.c:8:30: warning: trigraph ??> converted to...

How to set “No (/INCREMENTAL:NO)” in cmake to vs2010?

compilation,cmake,compiler-warnings
I want add this in my CMake, but i not know how to do this. How to set "No (/INCREMENTAL:NO)" in cmake? No (/INCREMENTAL:NO) Thanks....

How can I make my program compile without warning?

c,linux,gcc,compilation,compiler-warnings
I should compile my program with spec flags to gcc. Then gcc complained about return values not taken care of. WhenI use variables to take the return values then gcc complains again: $ gcc -pedantic -Wall -ansi -O4 miniShell.c miniShell.c: In function ‘cd’: miniShell.c:108:9: warning: variable ‘other_return’ set but not...

unchecked call to … as member of the raw type

java,generics,compiler-warnings,unchecked
I am getting the compiler warning: warning: [unchecked] unchecked call to setView(V) as a member of the raw type AbstractPresenter this.presenter.setView(this); where V is a type-variable: V extends AbstractView declared in class AbstractPresenter The code of the AbstractPresenter Class is the following: public abstract class AbstractPresenter<V extends AbstractView, M> implements...

Warning about function prototype even when the function takes arguments

c,compiler-warnings,function-prototypes
I have a simple function in C which takes int* argument and I have the declaration of it in the header file like this: void mapAuditFioError(int *errno); But compiler cirbs compiling the files including this header as follows: "warning: function declaration isn't a prototype" and also: "warning: passing argument 1...

Prevent ObsoleteAttribute warning bubbling up call stack

c#,visual-studio,warnings,compiler-warnings,suppress-warnings
I have a class using a deprecated assembly (System.Data.OracleClient). At compile time this results in a message 'MethodName()' is obsolete: 'OracleConnection has been deprecated. We can't replace this assembly and we are now trying to remove all warnings generated at compile time so that new warnings are clear to us....

Compiler behavior and “register storage class specifier is deprecated”

c++,c++11,compiler-warnings
I'm testing some C++ code with -std=c++11. I noticed a warning I had not seen before: 'register' storage class specifier is deprecated What does the standard say about this (other than its deprecated)? Is it implementation defined? Will compilers take it as a hint and try to put the value...

Unchecked warnings are not removed with Javac @SuppressWarnings annotation

java,compilation,warnings,javac,compiler-warnings
I cannot remove my warnings with unchecked cast. I believe this is very strange because I have added the @SuppressWarnings("unchecked") annotation on the method but the Javac still showing the warnings. [unchecked] unchecked cast (List<Integer>) getObject(LIST); return (List<Integer>) getObject(LIST); required: List<Integer> found: Object I have create an Example, It throws...

How to remove 100s of warnings “implicit conversion loses integer precision: 'NSInteger' (aka 'long') to 'int'” I got after updating to arm64?

objective-c,compiler-warnings,nsregularexpression,arm64,xcode6.3
Problem: Yesterday I converted a large project of mine to support arm64 and after that I got 500+ warnings at once. About 70% of them are where NSInteger is being assigned to int or vice versa, and remaining are where NSUInteger is formatted in NSString like this: NSInteger a =...

Disadvantages of using the `-Wextra` flag when compiling in GCC

c,gcc,code-analysis,compiler-warnings,compiler-flags
I know that one should always compile with both -Wall and -Wextra as they enable warnings and help us to understand our mistake, if any. I've read that the -Wextra compiler flag is not recommended to use because it is too verbose with a lot of false positives. I was...

Malloc vairables in seperate function results in “uninitialized in this function”

c,variables,malloc,warnings,compiler-warnings
Trying to simplify my code and I thought I'd be smart by mallocing all the variables in a function in a seperate function to remove big code chunks. However when I try to malloc some variables, the compiler returns: warning: ‘roomString’ is used uninitialized in this function [-Wuninitialized] Heres the...

Does Roslyn actually allow you to manipulate TreatWarningsAsErrors for a CSharp project?

c#,msbuild,compiler-warnings,roslyn
I'm trying to retrieve the setting TreatWarningsAsErrors, but I'm unable to find it for a project of my loaded solution. What I'm trying to accomplish, is to get the setting from the project files, and set it to true, if it's not already that. Next, I want to let Roslyn...

Using generics and trying to get rid of the unsafe operations warning

java,generics,compiler-warnings
Here is my code, but I keep getting the "Note: LinkedListAdd.java uses unchecked or unsafe operations." I'm trying to do what I can to get rid of it, but nothing seems to be working. The base class compiles fine and has no warning, and the check seems to be coming...

“initialization makes integer from pointer without a cast” waning in array initialization

c,arrays,pointers,char,compiler-warnings
I am now starting to learn C. I would like to know why I get the warning. I declared a bidimensional char array, but why the character "d" is not allowed? char array[3][3] = {{1,"d",3},{3,2,1},{2,1,3}}; ...

Suppress F# Compiler Warning: Possible incorrect indentation: this token is offside of context

unit-testing,f#,compiler-warnings,readability,xunit
I have some xunit tests I would like to layout as follows for readability: [<Fact>] let ``Has Hash Code 2``() = target.GetHashCode().ShouldBe 2 [<Fact>] let ``ToString yields two``() = target.ToString().ShouldBe "two" [<Fact>] let ``Has underlysing type int``() = target.GetUnderlyingType().ShouldBe typeof<int> I'm getting a compiler warning on the let statements: "Possible...

Suppress Swift compiler warning

ios,swift,closures,compiler-warnings,suppress-warnings
I'm using the Nimble assertion framework for unit testing in Swift (Xcode 6.3 beta). It works fine, but the compiler gives a warning for one of the lines in the Nimble source code: public func expect<T>(expression: () -> T?, file: String = __FILE__, line: UInt = __LINE__) -> Expectation<T> {...

Recipes on how to supress / fix “Implicit conversion changes signedness” warning

objective-c,xcode,compiler-warnings
I'm modernizing a legacy project and I enabled -Wconversion flag on Xcode. Now I have a lot of warning like Implicit conversion changes signedness: 'NSUInteger' (aka 'unsigned long') to 'NSInteger' (aka 'long') using code like the following while interacting with a UITableView Item *item = [self.items objectAtIndex:indexPath.row]; row is defined...

Why gcc does not give a warning or error when invalid mode is used in fopen()?

c,gcc,file-io,compiler-errors,compiler-warnings
I am practicing some practice questions in FILE IO in C. Below is one of the programs. #include<stdio.h> #include<stdlib.h> int main() { char fname[]="poem.txt"; FILE *fp; char ch; fp = fopen ( fname, "tr"); if (fp == NULL) { printf("Unable to open file...\n"); exit(1); } while((ch =fgetc(fp)) != EOF) {...

Swift - Compiler warns i haven't unwrapped an optional but then forces me to unwrap using ! rather than?

swift,xcode6,compiler-warnings,optional-values,forced-unwrapping
I've got an error in my code where the compiler gives a warning to unwrap an optional with the message Value of optional type 'NSDate?' not unwrapped; did you mean to use '!' or '?'? My code is let formatter = NSDateFormatter() let dob = currUser.valueForKey(userTextFieldKeyNames[i]) as? NSDate let dobText...

How to fix compiler warning on scala.xml.Elem

xml,scala,compiler-warnings
The following code generates this compilation warning : A repeated case parameter or extracted sequence should be matched only by a sequence wildcard (_*) import scala.xml.Elem def matchElem(e: Elem) = e match { case <source/> => "match!" } How to fix that ?...

Ignoring return value of fscanf and Segmentation fault

c,segmentation-fault,fopen,compiler-warnings,fscanf
I was wondering how to solve a Core dumped issue on my C code. When I compile it with: g++ -g MatSim.cpp -o MatSim -lstdc++ -O3, I get three warnings, this is one (The other two are similar and are only differentiated by the string variable name): MatSim.cpp: In function...

What does i = (i, ++i, 1) + 1; do?

c,expression,compiler-warnings,comma-operator
After reading this answer about Undefined behavior and sequence points, I wrote a small program: #include <stdio.h> int main(void) { int i = 5; i = (i, ++i, 1) + 1; printf("%d\n", i); return 0; } and the output is 2. Oh God, I didn't see the decrementation comming! Can...

msvc precompiled header warning suppress

c++,visual-c++,compiler-warnings,precompiled-headers
In my C++ project, I use precompiled headers as a compile time optimization. However, when I enable /Wall option in the compiler settings, I am not able to suppress any of warnings in the precompiled header file. Header File: #ifndef _PRECOMPILED_H #define _PRECOMPILED_H #pragma warning(push, 0) #pragma warning(disable: 4514) #include...

Pointer parameter was set but never used warning

c,pointers,compiler-warnings,suppress-warnings,keil
I have the following function: void foo(char *ptr_1) { char *ptr_2; bar(ptr_2); ptr_1 = ptr_2; } And get this warning: parameter "ptr_1" was set but never used I understand that the warning is technically true, but is irrelevant at the same time. I could suppress it with: (void)(ptr_1) But is...

Can't suppress warnings on an older GCC

c,gcc,compiler-warnings
I'm working with some autogenerated code that tends to have lines like void f(int16_t a) { if (a < INT32_MAX) ... } Which obviously produce warnings such as: warning: comparison is always true due to limited range of data type I can't change the GCC command line options, I can...

Best way to avoid 'control reaches end of non-void function' warning in release mode

c++,return-value,compiler-warnings,suppress-warnings
I have a class (here MyObject) with a function returning a name by refererence depending on the internal type of the object. Moreover, this function can only be called for some values of the internal type. /** * \brief Return the name depending of the internal type * \pre The...

Java version when using older target/source the api of the new java version is available [duplicate]

java,compiler-warnings
This question already has an answer here: Why javac “-source” flag doesn't work? 3 answers I have java 8 installed and compile my code to target and source 1.6. That works but i don't want the code to compile if there is a java 8 specific function in the...

IntelliJ command line compiler

java,command-line,intellij-idea,compiler-warnings,headless
I'm searching for an automated way to collect all the IntelliJ static code analysis warnings (compiler and inspections) without having to run a UI and click on buttons. Ideally I'd like run the IntelliJ compiler from the command line and have it log all warnings into a file. Is this...

How can I create custom compiler warnings in java?

java,concurrency,semaphore,compiler-warnings
I'm looking for something that's similar to implementing the java.lang.AutoCloseable interface, where a compiler warning indicating Resource leak: 'xxxx' is never closed is generated. The use case for this is in a wrapper around a Synchronized Collection in java. The wrapper has an internal semaphore to prevent concurrent modification of...

How to have gcc warn about conversions from uint32_t to uint64_t?

c++,gcc,compiler-warnings
Let's take the following simple example: #include <vector> #include <cstdint> using ::std::vector; using ::std::uint64_t; using ::std::uint32_t; int main(int argc, char *argv[]) { vector<uint64_t> v; uint32_t i = 1; v.push_back(i); return 0; } When I compile it with: g++ -std=c++11 -Wall -Wconversion -Wpedantic a.cpp I don't get any conversion error. However,...

Warning when trying to initialize a 2D struct array with two initializer lists

c,arrays,multidimensional-array,initialization,compiler-warnings
I am trying to initialize a 2D array of user defined type to zero by using following line, qmf_t X_hybrid_left[32][32] = {{0}}; Where qmf_t is a user defined type. Here I get the compiler warning, warning: missing braces around initializer [-Wmissing-braces]" But if I use, qmf_t X_hybrid_left[32][32] = {{{0}}};, i.e....