compiler-warnings

Impact on style of GHC -Wall

[亡魂溺海] 提交于 2019-12-02 20:24:30
It is considered good practice to enable GHC warnings with -Wall . However, I've found out that fixing those warnings has a negative effect for some types of code constructs. Example 1: Using the do-notation equivalent of f >> will generate a warning if I don't explicitly use the _ <- f form: Warning: A do-notation statement discarded a result of type Char. Suppress this warning by saying "_ <- f", or by using the flag -fno-warn-unused-do-bind I understand that I can forget to do something with the result of f . However, it is legitimate to ignore the result (very common in parsers). There is

Disable GCC “may be used uninitialized” on a particular variable

拈花ヽ惹草 提交于 2019-12-02 17:59:19
I'm getting this warning on a stack variable: warning: object.member may be used uninitialized in this function In this case I do not wish to force initialization to just to get rid of the warning as it consumes CPU cycles. The variable is a POD structure so a memset on it is not zero cost. I can verify that the variable is never used uninitialized, so I'd just like to suppress the warning for it. In general I do want the warning, just not on this particular variable in this particular scenario. How can I suppress the warning? Looks like the pragma diagnostics are the correct way to go but

Eclipse different behaviour for “Unchecked” warning due to “Potential heap pollution via varargs parameter”. How to fix?

喜你入骨 提交于 2019-12-02 15:29:12
问题 I have a simple Entry object for populating a list public class Entry { //fields public Entry(int a, String b, String c) { //... } //some getters } and an AsyncTask that retrieves the entries. On its onProgressUpdate ... (here) | @Override V protected void onProgressUpdate(List<Entry>... param) { for (Entry e : param[0]) myAdapter.add(e); progressBar.incrementProgressBy(1); myAdapter.notifyDataSetChanged(); } I have the warning: Type safety: Potential heap pollution via varargs parameter

Generify JSONObject string keys

痞子三分冷 提交于 2019-12-02 13:15:24
I have existing code which use org.json.JSONObject 's Iterator JSONObject obj = new JSONObject(); obj.put("key1", "value1"); obj.put("key2", "value2"); Iterator keys = obj.keys(); ... With compile warning Iterator is a raw type. References to generic type Iterator<E> should be parameterized I can update to generic version: Iterator<?> keys = obj.keys(); But isn't there a way to "generify" JSONObject with String keys? I find this answer but its suggestion doesn't compiled JSONObject<String,Object> obj=new JSONObject<String,Object>(); EDIT Using Iterator<String> keys = obj.keys(); I'm getting a

correct method to get the unsigned char pointer length

一笑奈何 提交于 2019-12-02 11:31:25
问题 I am using strlen function to get the length of unsigned char pointer. But VS compiler throws the following warning. unsigned char myString[] = "This is my string"; unsigned char* tmpBuffer = &myString[0]; size_t size = strlen(tmpBuffer); warning C4057: 'function' : 'const char *' differs in indirection to slightly different base types from 'unsigned char *' So what is the proper way to get unsigned char pointer size to get rid of the warning. 回答1: strlen((const char*)tmpBuffer); Let you get

Eclipse different behaviour for “Unchecked” warning due to “Potential heap pollution via varargs parameter”. How to fix?

放肆的年华 提交于 2019-12-02 05:22:56
I have a simple Entry object for populating a list public class Entry { //fields public Entry(int a, String b, String c) { //... } //some getters } and an AsyncTask that retrieves the entries. On its onProgressUpdate ... (here) | @Override V protected void onProgressUpdate(List<Entry>... param) { for (Entry e : param[0]) myAdapter.add(e); progressBar.incrementProgressBy(1); myAdapter.notifyDataSetChanged(); } I have the warning: Type safety: Potential heap pollution via varargs parameter param This happens on a PC Linux 64bit while the opposite warning is shown on a notebook with the same

correct method to get the unsigned char pointer length

三世轮回 提交于 2019-12-02 04:11:34
I am using strlen function to get the length of unsigned char pointer. But VS compiler throws the following warning. unsigned char myString[] = "This is my string"; unsigned char* tmpBuffer = &myString[0]; size_t size = strlen(tmpBuffer); warning C4057: 'function' : 'const char *' differs in indirection to slightly different base types from 'unsigned char *' So what is the proper way to get unsigned char pointer size to get rid of the warning. strlen((const char*)tmpBuffer); Let you get rid of the note. Here you are typecasting it to the appropriate type that is being expected by the strlen()

Ignore clang warnings related to property

两盒软妹~` 提交于 2019-12-02 03:39:50
问题 i want to ignore these warnings these warning appeared when i used valid architechtures : arm64 armv7 armv7s these type of warnings appearing in many headers . i want to ignore these warnings just like clang does for deprecated warnings. #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" i want something like this or any compiler flags to ignore these warnings 回答1: If you go to the log navigator (the last tab on the left panel in Xcode), you can expand

Why doesn't gcc o warn when size of array is uninitialized in this code?

假如想象 提交于 2019-12-02 02:49:36
问题 Okay, so this is a stripped down variant of a bug I had. The bug was that I initialized an array using a variable that wasn't initialized. Earlier I used a function to declare the number of elements using a function, but after a cleanup I forgot about it and moved all declarations to the top of the function. I used the flags -std=c99 -Wall -Wextra -pedantic -O , and usually gcc warns about values being used before they are uninitialized, but in this specific case it didn't. So, my question is

User defined compiler warning or error in C# [duplicate]

╄→гoц情女王★ 提交于 2019-12-02 00:39:00
问题 This question already has answers here : Custom Compiler Warnings (10 answers) Closed 5 years ago . Is it possible to have some code let the compiler generate a compile warning or error? Maybe with Attributes? ** Having the first answer and a few comments I realize my question is not as a clear as I expected and wanted it to be. I apologize. Hopefully all contributers are still with us. ** So I am more looking towards an internal DSL. S.Th. like [MustAssign] public string Val {get; set;] 回答1: