compiler-warnings

Java: properly checked class instantiation using reflection

坚强是说给别人听的谎言 提交于 2019-12-05 08:53:30
I'm trying to use one of the simplest forms of reflection to create an instance of class: package some.common.prefix; public interface My { void configure(...); void process(...); } public class MyExample implements My { ... // proper implementation } String myClassName = "MyExample"; // read from an external file in reality Class<? extends My> myClass = (Class<? extends My>) Class.forName("some.common.prefix." + myClassName); My my = myClass.newInstance(); Typecasting unknown Class object we've got from Class.forName yields a warning: Type safety: Unchecked cast from Class<capture#1-of ?> to

How to get Intellij Idea to display compilation warnings?

我只是一个虾纸丫 提交于 2019-12-05 08:20:53
问题 I'm working with Intellij Idea 10 and Java 6 JDK Update 7. When I run Build --> Rebuild Project command, and the (javac) compilation generates warnings, Idea doesn't display what those warnings exactly are in the Messages view. I just see an "Information: XX warnings" node, but no way to expand it to see the actual warnings. Or I just see a message "Compilation completed successfully with XX warnings" on the status bar. For errors, Idea displays the error information (error message, filename,

What is the purpose of gcc's -Wbad-function-cast?

隐身守侯 提交于 2019-12-05 08:17:35
As advised by an answer here, I turned on -Wbad-function-cast to see if my code had any bad behavior gcc could catch, and it turned up this example: unsigned long n; // ... int crossover = (int)pow(n, .14); (it's not critical here that crossover is an int ; it could be unsigned long and the message would be the same). This seems like a pretty ordinary and useful example of a cast. Why is this problematic? Otherwise, is there a reason to keep this warning turned on? I generally like to set a lot of warnings, but I can't wrap my mind around the use case for this one. The code I'm working on is

How to create custom warning in Eclipse for a standard Java API

房东的猫 提交于 2019-12-05 07:32:25
问题 I want Eclipse to warn the use the of old Date/Calendar API in my Java project, allowing only the Java 8 brand new Date-Time API as the one beeing used in the source. How can I configure Eclipse to display a warning if, for example, java.util.Date is used? I happly accept additional comments on this approach, as well for other alternatives. I am aware that I should also apply this type of validation in the CI build, as well that Java Policy might be another alternative. 回答1: You can add an

How to wisely interpret this compiler warning?

浪尽此生 提交于 2019-12-05 07:02:58
When I executed the code of this question , I got this warning: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long int' [-Wformat=] printf("P-Q: %d, P: %d, Q: %d", (p - q), p, q); ~^ ~~~~~~~ %ld As a reflex fix, I used %ld to print the subtraction of two pointers. And the compiler agreed. Fortunately, I saw a comment from another user mentioning that %td should be used, since the result type of the subtraction is ptrdiff_t . This answer confirms this claim. Now from GCC's header file of stddef.h , I can see that these types are equivalent in this case: typedef _

The assignment to variable has no effect?

喜欢而已 提交于 2019-12-05 06:32:45
When I do this: count = ++count; Why do i get the warning - The assignment to variable count has no effect ? This means that count is incremented and then assigned to itself or something else ? Is it the same as just ++count ? What happens in count = count++; ? Why don't I get a warning for this ? count++ and ++count are both short for count=count+1 . The assignment is built in, so there's no point to assigning it again. The difference between count++ (also knows as postfix ) and ++count (also known as prefix ) is that ++count will happen before the rest of the line, and count++ will happen

How to enable all compiler warnings in CLion?

不羁岁月 提交于 2019-12-05 05:15:29
I want to see all compiler warnings in CLion. I don't want them treated as errors, but I want to inspect all of them. How can I do this? Gluttton Try to set compiler flag in CMakeLists.txt : set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra") Related question: How to enable C++11 in CLion? Rebuild your entire project. Most compilers don't rebuild every file when you just press build, so you will only see warnings from files that were changed. For C: set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra") 来源: https://stackoverflow.com/questions/31790467/how-to-enable-all-compiler-warnings-in

c++ Builder xe5 Error detected (LME288)

∥☆過路亽.° 提交于 2019-12-05 04:45:09
c++ Builder xe5 [ilink32 Error] Error: Unable to perform link [ilink32 Warning] Warning: Error detected (LME288) that happened when i tried to compile a test project c++ builder xe5 on windows xp Barry Andrews I got some information on this from Embarcadero which may help. The error is an "out of memory", error. The reason for "Out Of Memory" errors (which come in different guises) in the linker, is that the linker has to pre-allocate memory in contiguous heaps that it then uses as it links, in the past these heaps could not be adjusted, we had to do a best guess, so in the new 64-bit linker

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

我的未来我决定 提交于 2019-12-05 04:29:41
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 quite surprised on reading this. So I started googling about it but I didn't get any answer as all the search results showed was "what does the -Wextra flag do?". So, my questions are In which all situations does the -Wextra flag emit uneccessary warnings? Is it possible to stop the -Wextra flag from enabling the other flags that

Compiler gets warnings when using strptime function (C)

可紊 提交于 2019-12-05 03:44:53
Typing man strptime it sais that this function needs to have declared _XOPEN_SOURCE and included time.h header. I did it. But, when I try to compile my code I get: ./check.c:56: warning: implicit declaration of function ‘strptime’ Look at my code: int lockExpired(const char *date, const char *format, time_t current) { struct tm *tmp = malloc(sizeof(struct tm *)); time_t lt; int et; strptime(date, format, tmp); lt = mktime(tmp); et = difftime(current, lt); if (et < 3600) return -et; return 1; } Also the function declaration is: char *strptime(const char *s, const char *format, struct tm *tm);