Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
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 11:51 Go to next message
Ali Baharev is currently offline Ali Baharev
Messages: 5
Registered: January 2012
Junior Member
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:
in->seekg(i*BLOCK_SIZE);

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 17:00 Go to previous messageGo to next message
Hermann Vosseler is currently offline Hermann Vosseler
Messages: 7
Registered: July 2009
Junior Member
Ali Baharev wrote on Sun, 08 January 2012 11:51
Code 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 #776608 is a reply to message #776601] Sun, 08 January 2012 17:31 Go to previous messageGo to next message
Ali Baharev is currently offline Ali Baharev
Messages: 5
Registered: January 2012
Junior Member
Thanks 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.
Re: Eclipse CDT Code Analysis says error, g++ and cl.exe are OK with it [message #776729 is a reply to message #776608] Mon, 09 January 2012 02:05 Go to previous messageGo to next message
Dirk Wibben is currently offline Dirk Wibben
Messages: 50
Registered: February 2010
Member
AFAIK is Codan a Build-In feature of CDT.
NO external tool is used for it.

Greets
Dirk


Best regards
Dirk
Re: Eclipse CDT Code Analysis says error, g++ and cl.exe are OK with it [message #776775 is a reply to message #776729] Mon, 09 January 2012 04:03 Go to previous messageGo to next message
Ali Baharev is currently offline Ali Baharev
Messages: 5
Registered: January 2012
Junior Member
Thanks. Yes, it is Codan, and others are having the same issue:



Code analysis - false syntax & semantic errors?
Eclipse CDT shows wrongly errors
Codan Semantic & Syntax can't be distinguished from compiler errors in the ed...
Codan errors

Even though it is claimed that the issue is solved/fixed/resolved, it is still there...

Another bug report? Or the best I can do is the workaround proposed by Ichthyo?

(Excellent, I can not post the links!)

[Updated on: Sat, 14 January 2012 13:56]

Report message to a moderator

Re: Eclipse CDT Code Analysis says error, g++ and cl.exe are OK with it [message #776797 is a reply to message #776601] Mon, 09 January 2012 04:34 Go to previous messageGo to next message
Harry Houdini is currently offline Harry Houdini
Messages: 131
Registered: February 2010
Senior Member
Hermann Vosseler wrote on Sun, 08 January 2012 23:00
Especially, it seems to be unable to pick up template specialisations properly. (It also seems to have problems taking typedefs into account).

It seems also unable to find members inherited from templated classes.
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 04:56 Go to previous messageGo to next message
Axel Mueller is currently offline Axel Mueller
Messages: 1949
Registered: July 2009
Senior Member
Ali Baharev wrote on Sun, 08 January 2012 23:31
Thanks 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
double exp(double)
.
I guess you are calling this function with float parameters. To fix the issue you can either use explicitly
float expf(float)
or cast your parameters to double.


Before you ask
- search this forum
- see the FAQ http://wiki.eclipse.org/CDT/User/FAQ
- google
Re: Eclipse CDT Code Analysis says error, g++ and cl.exe are OK with it [message #776881 is a reply to message #776809] Mon, 09 January 2012 08:02 Go to previous messageGo to next message
Ali Baharev is currently offline Ali Baharev
Messages: 5
Registered: January 2012
Junior Member
No, I am calling exp with deriv_type. I tried the explicit casting back then, it did not help, neither did manual friend namespace injection (exp is a friend of deriv_type). I do NOT get any compiler warning.

The indexer is ready, it is a small project anyhow. There are no predefined symbols.
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 09:59 Go to previous messageGo to next message
Axel Mueller is currently offline Axel Mueller
Messages: 1949
Registered: July 2009
Senior Member
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
a[i]+b[i]/(T+c[i])
is not of type
const deriv_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.


Before you ask
- search this forum
- see the FAQ http://wiki.eclipse.org/CDT/User/FAQ
- google
Re: Eclipse CDT Code Analysis says error, g++ and cl.exe are OK with it [message #776933 is a reply to message #776927] Mon, 09 January 2012 10:07 Go to previous messageGo to next message
Thomas .
Messages: 32
Registered: July 2009
Member
On 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
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 10:17 Go to previous messageGo to next message
Axel Mueller is currently offline Axel Mueller
Messages: 1949
Registered: July 2009
Senior Member
Thomas wrote on Mon, 09 January 2012 16:07
On 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.


Before you ask
- search this forum
- see the FAQ http://wiki.eclipse.org/CDT/User/FAQ
- google
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 10:32 Go to previous messageGo to next message
Thomas .
Messages: 32
Registered: July 2009
Member
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 #776958 is a reply to message #776955] Mon, 09 January 2012 10:39 Go to previous messageGo to next message
Axel Mueller is currently offline Axel Mueller
Messages: 1949
Registered: July 2009
Senior Member
Thomas wrote on Mon, 09 January 2012 16:32

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!

http://www.richelbilderbeek.nl/CppConstReturnType.htm

http://developer.kde.org/~wheeler/cpp-pitfalls.html
const Return Values


Before you ask
- search this forum
- see the FAQ http://wiki.eclipse.org/CDT/User/FAQ
- google
Re: Eclipse CDT Code Analysis says error, g++ and cl.exe are OK with it [message #777180 is a reply to message #776809] Mon, 09 January 2012 20:28 Go to previous messageGo to next message
Hermann Vosseler is currently offline Hermann Vosseler
Messages: 7
Registered: July 2009
Junior Member
Axel Mueller wrote on Mon, 09 January 2012 04:56
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.


... 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 03:37 Go to previous messageGo to next message
Axel Mueller is currently offline Axel Mueller
Messages: 1949
Registered: July 2009
Senior Member
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).


Before you ask
- search this forum
- see the FAQ http://wiki.eclipse.org/CDT/User/FAQ
- google
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 13:52 Go to previous messageGo to next message
Ali Baharev is currently offline Ali Baharev
Messages: 5
Registered: January 2012
Junior Member
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 Sad
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 18:00 Go to previous messageGo to next message
Angus Henderson is currently offline Angus Henderson
Messages: 13
Registered: October 2011
Junior Member

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 03:06 Go to previous messageGo to next message
Jan Pohanka is currently offline Jan Pohanka
Messages: 28
Registered: June 2011
Junior Member
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 05:22 Go to previous messageGo to next message
Axel Mueller is currently offline Axel Mueller
Messages: 1949
Registered: July 2009
Senior Member
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.


Before you ask
- search this forum
- see the FAQ http://wiki.eclipse.org/CDT/User/FAQ
- google
Re: Eclipse CDT Code Analysis says error, g++ and cl.exe are OK with it [message #912861 is a reply to message #912838] Fri, 14 September 2012 05:51 Go to previous messageGo to next message
Jan Pohanka is currently offline Jan Pohanka
Messages: 28
Registered: June 2011
Junior Member
Your proposal seems very reasonable to me. I wonder why there are no votes yet. Every C/C++ developer using Eclipse that I know is usually very confused by these kind of error. I will tell them to vote too Wink

regards
Jan
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 11:02 Go to previous messageGo to next message
slajerek . is currently offline slajerek .
Messages: 19
Registered: April 2010
Junior Member
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 11:05]

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 19:12 Go to previous message
Nobody Mising name is currently offline Nobody Mising name
Messages: 75
Registered: July 2010
Member
Missing name Mising name wrote on Mon, 25 March 2013 11:02
why 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.
Previous Topic:Auto complete not working for opengl?
Next Topic:Invoking CDT debugger Programmatically
Goto Forum:
  


Current Time: Sat Aug 23 03:40:10 EDT 2014

Powered by FUDForum. Page generated in 0.02624 seconds