Home » Language IDEs » C / C++ IDE (CDT) » Eclipse CDT Code Analysis says error, g++ and cl.exe are OK with it(How to set the Code Analysis properly?)
Eclipse CDT Code Analysis says error, g++ and cl.exe are OK with it [message #776516] |
Sun, 08 January 2012 16:51  |
Eclipse User |
|
|
|
Code Analysis gives errors to codes that are OK, neither g++ nor cl complains about it, not even a warning.
How can I resolve these annoying issues?
Ubuntu 11.10 x86_64
CDT Build id: 20110916-0149
gcc version 4.6.1 (Ubuntu/Linaro 4.6.1-9ubuntu3)
Example:
Description Resource Path Location Type
Invalid arguments '
Candidates are:
std::basic_istream<char,std::char_traits<char>> & seekg(?)
std::basic_istream<char,std::char_traits<char>> & seekg(long int, enum std::_Ios_Seekdir)
' FileAsBlockDevice.cpp /sd_card line 69 Semantic Error
p[i] = exp(a[i]+b[i]/(T+c[i]));
Description Resource Path Location Type
Invalid arguments '
Candidates are:
double exp(double)
const deriv_type exp(const deriv_type &)
' bp_calc.cpp /fw_sweep line 118 Semantic Error
|
|
|
Re: Eclipse CDT Code Analysis says error, g++ and cl.exe are OK with it [message #776601 is a reply to message #776516] |
Sun, 08 January 2012 22:00   |
Eclipse User |
|
|
|
Ali Baharev wrote on Sun, 08 January 2012 11:51Code Analysis gives errors to codes that are OK, neither g++ nor cl complains about it, not even a warning.
Indeed, thats an annoying problem and somehow defeats the whole purpuse of "code analysis". The obvious quick fix is to go to the preferences and turn the corresponding problem type into "Info".
Unfortunately I've found no way to differentiate those settings. Thus, you'll quickly end up silencing all of the important warnings this way. The CDT code analysis seems to bail ot on a lot of situations. Especially, it seems to be unable to pick up template specialisations properly. (It also seems to have problems taking typedefs into account). Which -- if you e.g. use the Boost libararies or do a bit of template metaprogramming yourselves -- leads to plastering almost every line with false alarms.
I'd love to hear a better solution -- because actually having an code analysis as you type (as in Java or Scala) would certainly be a killer feature.
-- Ichthyo
|
|
| | | | |
Re: Eclipse CDT Code Analysis says error, g++ and cl.exe are OK with it [message #776809 is a reply to message #776608] |
Mon, 09 January 2012 09:56   |
Eclipse User |
|
|
|
Ali Baharev wrote on Sun, 08 January 2012 23:31Thanks for the answer! Do you happen to know how the code analysis is done by Eclipse? What is the name of the tool? I always thought it just invokes the compiler for syntax check but this issue indicates it does something else.
The internal code analysis CODAN is bases on the indexer. So if the index is not complete you will get false CODAN errors. Sometimes the index is not complete due to missing include paths or predefined symbols which can be fixed.
In your case the indexer does not know which function to use because there are several function with the same name but different signature i.e. different parameter types. Sometimes you can fix the CODAN error by explicitly casting to the correct type (the compiler does this normally for you and will issue a warning only if the cast might cause precision loss).
In your code you are using .
I guess you are calling this function with float parameters. To fix the issue you can either use explicitly or cast your parameters to double.
|
|
| |
Re: Eclipse CDT Code Analysis says error, g++ and cl.exe are OK with it [message #776927 is a reply to message #776881] |
Mon, 09 January 2012 14:59   |
Eclipse User |
|
|
|
Quote:No, I am calling exp with deriv_type.
OK, I did not read your message carefully enough.
Quote:I do NOT get any compiler warning.
Well, the purpose of the static code analysis is to find bugs that a compiler will not find! (of course, false positives aside)
Select exp in the editor and press F3 to go to the declaration of exp(deriv). Does it work or will it bring up a dialog showing different versions of exp? In this case your argument is not of type .
Ah, wait. I guess the problem is not the parameter but the type of the return value. You declared [b]const[/b] deriv_type exp(..) . So p[i] must be declared const.
As a note, CODAN reports different types of errors. Yours is a so-called "Semantic Error". Usually nothing critical but it is better to address it.
|
|
| |
Re: Eclipse CDT Code Analysis says error, g++ and cl.exe are OK with it [message #776943 is a reply to message #776933] |
Mon, 09 January 2012 15:17   |
Eclipse User |
|
|
|
Thomas wrote on Mon, 09 January 2012 16:07On a sidenote:
Wouldn't it be helpful to switch off individual Codan message instances rather than turning off a whole message class?
When Ali has inspected his code and found it perfect, he should have the option to mark the Codan message as "ignored" (or something like that).
Thomas
You can switch off individual Codan checkers for certain files. Open Project Properties->C/C++ General->Code analysis and then customize.
Some checkers can be disabled by comments in the code (e.g. the "no break" message in a switch case statement).
But I think in the case of Ali there is a truly a (semantic) error in his code.
|
|
|
Re: Eclipse CDT Code Analysis says error, g++ and cl.exe are OK with it [message #776955 is a reply to message #776943] |
Mon, 09 January 2012 15:32   |
Eclipse User |
|
|
|
Quote:Ah, wait. I guess the problem is not the parameter but the type of the return value. You declared [b]const[/b] deriv_type exp(..) . So p[i] must be declared const.
I can't see the semantic error you are mentioning. If you would declare p[i] as const, then you would not be able to assign a value to it. But maybe I got it wrong, so if you would be so kind to explain the semntic error... Thank you very much in advance!
|
|
| |
Re: Eclipse CDT Code Analysis says error, g++ and cl.exe are OK with it [message #777180 is a reply to message #776809] |
Tue, 10 January 2012 01:28   |
Eclipse User |
|
|
|
Axel Mueller wrote on Mon, 09 January 2012 04:56The internal code analysis CODAN is bases on the indexer. So if the index is not complete you will get false CODAN errors. Sometimes the index is not complete due to missing include paths or predefined symbols which can be fixed.
In your case the indexer does not know which function to use because there are several function with the same name but different signature i.e. different parameter types.
... while the compiler certainly knows, based on the rules of the language. Otherwise there would be an ambiguity and thus an compiler error.
Generally speaking, CODAN is a very promising feature, just it doesn't seem to be "there yet". We all know that the rules of C++ can be quite intricate in all gory details. As it stands currently, CODAN doesn't seem to implement all of C++ and thus misses quite frequently things which are prefectly legal or also fails to warn on things where it should.
Just to give one very blatant example:
There is the warning "your class has virtual functions but is lacking a virtual dtor". We all agree that such a warning would be a very good thing.
Unfortunately:
- CODAN gives a false positive if your class is derived from an ABC, which defines exactly that virtual dtor
- CODAN fails to warn, when you don't declare your overriden function as "virtual", but fail to define that virtual dtor in the base class.
Of course we can start arguing about style now, but thats besides the pont.
Anyway, I think CODAN is going to be come a killer feature, once it gets most
aspects of the language right. We just need to be a bit more patient (or help with implementing what's missing?)
-- Ichthyo
|
|
|
Re: Eclipse CDT Code Analysis says error, g++ and cl.exe are OK with it [message #777294 is a reply to message #777180] |
Tue, 10 January 2012 08:37   |
Eclipse User |
|
|
|
Hermann Vosseler wrote on Tue, 10 January 2012 02:28
Generally speaking, CODAN is a very promising feature, just it doesn't seem to be "there yet".
Yeah, you are right. Unfortunately, there are still open issues. Therefore I have disabled some checks (e.g. virtual dtor!) and CODAN is only active when I open a file in the editor. In the Problems View I usually filter out the CODAN messages.
But work is continuing and you should see much better results with the next release in June (if you are brave you can already use a nightly build).
|
|
|
Re: Eclipse CDT Code Analysis says error, g++ and cl.exe are OK with it [message #779110 is a reply to message #777294] |
Sat, 14 January 2012 18:52   |
Eclipse User |
|
|
|
No matter how hard I look, I cannot see the "truly semantic error" in my code. I hope we both agree that if it is a "truly semantic error" then it should not compile without a warning both with g++ and cl.exe (all warnings are enabled).
I ended up turning of CODAN due to its annoying false error messages but it is rather a dirty workaround than a solution
|
|
|
Re: Eclipse CDT Code Analysis says error, g++ and cl.exe are OK with it [message #883593 is a reply to message #779110] |
Fri, 08 June 2012 22:00   |
Eclipse User |
|
|
|
I found two cases where I was getting incorrect CODAN errors.
1. if i use this syntax to declare a method:
void myfunc( myClass & classArg );
if i take out one of the spaces either side of the '&' errors go away
2. include files not found:
if CODAN says a reference in a headr file cannot be found, when it is found by
the compiler, i just include that header specifically in the offending file.
ANgus
|
|
|
Re: Eclipse CDT Code Analysis says error, g++ and cl.exe are OK with it [message #912777 is a reply to message #777294] |
Fri, 14 September 2012 07:06   |
Eclipse User |
|
|
|
Axel Mueller wrote on Tue, 10 January 2012 03:37
Yeah, you are right. Unfortunately, there are still open issues. Therefore I have disabled some checks (e.g. virtual dtor!) and CODAN is only active when I open a file in the editor. In the Problems View I usually filter out the CODAN messages.
But work is continuing and you should see much better results with the next release in June (if you are brave you can already use a nightly build).
Thank you Axel for this information. I was not aware of the possibility of filtering codan messages in the problems view. It is much better to use problems view now.
However, as we all probably agree CODAN code analysis still is not perfect (and I'm wondering if it ever be) especially for larger Makefile projects (eg. linux kernel, qt projects, ...) so I'd like to be able to distinguish the CODAN errors from compile errors even in editor view. Is there a way how to do it? I have found only severity settings (error, warning, info). This closed bug (https://bugs.eclipse.org/bugs/show_bug.cgi?id=329430) informs about some icons used to distinguish the problems, but in Eclipse Indigo I see only red underlines and red rectangles in the bar for both compiler and CODAN errors.
I think that editor should be useful even for non indexed project...
with best regards
Jan
|
|
|
Re: Eclipse CDT Code Analysis says error, g++ and cl.exe are OK with it [message #912838 is a reply to message #912777] |
Fri, 14 September 2012 09:22   |
Eclipse User |
|
|
|
Jan Pohanka wrote on Fri, 14 September 2012 09:06
However, as we all probably agree CODAN code analysis still is not perfect (and I'm wondering if it ever be) especially for larger Makefile projects (eg. linux kernel, qt projects, ...) so I'd like to be able to distinguish the CODAN errors from compile errors even in editor view. Is there a way how to do it? I have found only severity settings (error, warning, info). This closed bug (https://bugs.eclipse.org/bugs/show_bug.cgi?id=329430) informs about some icons used to distinguish the problems, but in Eclipse Indigo I see only red underlines and red rectangles in the bar for both compiler and CODAN errors.
I think that editor should be useful even for non indexed project...
with best regards
Jan
As you can see from the above mentioned bug report I did foresee problems with the CODAN icons in the editor. Unfortunately, I was ignored. I proposed then another enhancement https://bugs.eclipse.org/bugs/show_bug.cgi?id=368221
An option to use different colors for CODAN errors in the editor. You can add your vote if you like.
|
|
| |
Re: Eclipse CDT Code Analysis says error, g++ and cl.exe are OK with it [message #1023966 is a reply to message #912861] |
Mon, 25 March 2013 15:02   |
Eclipse User |
|
|
|
I do believe that CDT Code Analysis should be switched off by default. I spent a lot of time figuring out what's wrong with my project. Of course, the code analysis was wrong, hopefully I found this and switched off that broken feature completely. But my precious time was lost and it took me an hour or so. I assume every C++ developer has to go down this path, which in overall gives years of time effort lost.
Why developers of Eclipse are keeping features that certainly are broken (such as code analysis) set default to on? It's really annoying. From my perspective I do not care, but if something is telling me that I have an error in my code, which compiles, is written perfectly fine, but some analysis went wrong - then that feature should be called experimental and removed (in my example that was reference to a type which was defined, included but Eclipse have not found it for some reason and assumed it as "?"). Certainly, the CDT Code Analysis is such feature and I ALWAYS have problems with it, thus please tell me why it's in Eclipse's stable branch and turned on by default?
[Updated on: Mon, 25 March 2013 15:05] by Moderator Report message to a moderator
|
|
|
Re: Eclipse CDT Code Analysis says error, g++ and cl.exe are OK with it [message #1024161 is a reply to message #1023966] |
Mon, 25 March 2013 23:12  |
Eclipse User |
|
|
|
Missing name Mising name wrote on Mon, 25 March 2013 11:02why it's in Eclipse's stable branch and turned on by default?
A lot of features in CDT don't work correctly. For example "Rename Refactoring" can silently break code, should it also be excluded by default?
CDT indexer is not a compiler front-end for C++ (like clang) so it often fails to parse correct code. Also CDT is far from JDT (which contains compiler) where features just work.
|
|
|
Goto Forum:
Current Time: Sun Feb 09 19:13:17 GMT 2025
Powered by FUDForum. Page generated in 0.06281 seconds
|