Cppcheck 1.82 failed running analysis of the following simplified code:
#defineEVTDELEG(classname,arg1type)template<typenameT>\classC##classname{\public:\typedefvoid(T::*fnptr)(##arg1type);\C##classname(T*object,fnptrfn):m_object(object),m_fn(fn){}\voidInvoke(##arg1typevalue){\(m_object->*m_fn)(value);\}\private:\T*m_object;\fnptrm_fn;\};classEvtH{// For each of the events a delegate needs to be declared.EVTDELEG(CDG,bool)};voidmain() {return0;}
Thank you for the response. I am sorry for the delay (I had a vacation).
You are correct. With simplification of the original code I left return 0; while main() is void. Just replace void with int and this code compiles. I am using Visual Studio 2015 (C++ CLR). Nevertheless, CPPCheck should not fail such way despite the code is not compilable.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Ah ok, with Visual Studio i also do not get the preprocessor errors.
GCC and Visual Studio handle the token pasting operator differently:
According to https://complete-concrete-concise.com/programming/c/preprocessor-the-token-pasting-operator both compilers are working correctly, the standard does not define everything.
So i think Cppcheck should handle this code correctly too and should not issue an analysis failed warning.
I will create a ticket for that.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It seems to be really a duplicate of his older ticket and there the result was that it seems to be invalid code.
If you have any information/links that this is really valid code that should be accepted by static analyzers that may help.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I agree, you are right. ## is useless in this case. It concatenates an empty token with a token arg1type. Anyway, it is compilable by Visual Studio (at least 2017, without any error or warning).
This is a simplified fragment of a legacy code in our huge stream which is going to be replaced soon (I hope). Nevertheless, the point I wrote about this is that I considered Cppcheck encountered a serious internal error (because it "failed") which is good to report. Failure of a program represents a backlog from my point of view - therefore I just wanted to inform about such an issue to help to improve the behaviour of future versions of Cppcheck. It could inform the user in a better way than with a failure in my opinion.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
For information, I want simplecpp to be compatible with gcc/msvc.. but this feels like a bug in the msvc preprocessor so I will not try to implement this.
It could inform the user in a better way than with a failure in my opinion.
Ok. I have something else now. The following code gives: "[test.cpp:13]: (error) Array 'pdispparams->rgvarg[2]' accessed at index 2, which is out of bounds." This error message is suppressed if another assert() is added (just uncomment the last assert and you will see). I do not undersand the behaviour of CPPCheck here.
The following fragment of code is compilable in VS2017.
#include<atlbase.h>#include<assert.h>classCBBox{public:CBBox() {}STDMETHOD(Invoke)(DISPPARAMS*pdispparams,VARIANT*){assert(pdispparams->cArgs==3);assert(pdispparams->rgvarg[0].vt==VT_R8);assert(pdispparams->rgvarg[1].vt==VT_I4);assert(pdispparams->rgvarg[2].vt==VT_BSTR);//assert(pdispparams->rgvarg[3].vt == VT_BSTR); // Uncommenting this line suppresses the error message of the line belowCComBSTRname=pdispparams->rgvarg[2].bstrVal;returnS_OK;}};intmain() {return0;}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I can reproduce this with the current development version of Cppcheck:
$ ./cppcheck --debug-warnings array_outofbounds.cpp
Checking array_outofbounds.cpp ...
[array_outofbounds.cpp:13]: (error) Array 'pdispparams->rgvarg[2]' accessed at index 2, which is out of bounds.
[array_outofbounds.cpp:8]: (debug) Unknown type'pdispparams.'.
[array_outofbounds.cpp:11]: (debug) Unknown type'pdispparams.'.
IMHO the error is a false positive and i have no idea how Cppcheck knows (or think it knows) the size of the array pdispparams->rgvarg[]. I am not sure but guessing such things out of asserts is not yet implemented and even if it would be i can not see how this error is justified then.
But i am no insider so maybe one of the core developers has an idea what is going on here.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Cppcheck 1.82 failed running analysis of the following simplified code:
Online demo (http://cppcheck.sourceforge.net/demo/) reports:
I tried to create a ticket in Trac, but I was not able to create an account (tried https://webchat.freenode.net/?channels=#cppcheck and then also this forum: https://sourceforge.net/p/cppcheck/discussion/development/thread/34ddb3ae/#5be5).
How do you compile this code?
I tried g++ 6.4.0 with "g++ --std=c++17 analysis_failed.cpp" and got the following output:
Thank you for the response. I am sorry for the delay (I had a vacation).
You are correct. With simplification of the original code I left return 0; while main() is void. Just replace void with int and this code compiles. I am using Visual Studio 2015 (C++ CLR). Nevertheless, CPPCheck should not fail such way despite the code is not compilable.
Ah ok, with Visual Studio i also do not get the preprocessor errors.
GCC and Visual Studio handle the token pasting operator differently:
According to https://complete-concrete-concise.com/programming/c/preprocessor-the-token-pasting-operator both compilers are working correctly, the standard does not define everything.
So i think Cppcheck should handle this code correctly too and should not issue an analysis failed warning.
I will create a ticket for that.
I created the ticket: https://trac.cppcheck.net/ticket/8427
Thank you. Nevertheless, amai marked this as a duplicate ticket and closed it. I hope that the developers will finally take care about it.
It seems to be really a duplicate of his older ticket and there the result was that it seems to be invalid code.
If you have any information/links that this is really valid code that should be accepted by static analyzers that may help.
Please tell me why you have the ## in the code :
Is it by mistake?
This usage of ## seems pointless to me and it makes the code invalid/undefined.
I agree, you are right. ## is useless in this case. It concatenates an empty token with a token arg1type. Anyway, it is compilable by Visual Studio (at least 2017, without any error or warning).
This is a simplified fragment of a legacy code in our huge stream which is going to be replaced soon (I hope). Nevertheless, the point I wrote about this is that I considered Cppcheck encountered a serious internal error (because it "failed") which is good to report. Failure of a program represents a backlog from my point of view - therefore I just wanted to inform about such an issue to help to improve the behaviour of future versions of Cppcheck. It could inform the user in a better way than with a failure in my opinion.
For information, I want simplecpp to be compatible with gcc/msvc.. but this feels like a bug in the msvc preprocessor so I will not try to implement this.
Yes I totally agree. I created this issue: https://github.com/danmar/simplecpp/issues/121
Ok. I have something else now. The following code gives: "[test.cpp:13]: (error) Array 'pdispparams->rgvarg[2]' accessed at index 2, which is out of bounds." This error message is suppressed if another assert() is added (just uncomment the last assert and you will see). I do not undersand the behaviour of CPPCheck here.
The following fragment of code is compilable in VS2017.
I can reproduce this with the current development version of Cppcheck:
IMHO the error is a false positive and i have no idea how Cppcheck knows (or think it knows) the size of the array
pdispparams->rgvarg[]
. I am not sure but guessing such things out of asserts is not yet implemented and even if it would be i can not see how this error is justified then.But i am no insider so maybe one of the core developers has an idea what is going on here.