Eclipse signals an error but the code compiles - eclipse

I'm writing some C++ code with eclipe.
I have a strange behavior with vector objects.
When I use the method resize for example, Eclipse returns the following error:
#include "vector"
...
vector<int> a;
a.resize(5);
Error: Invalid arguments candidates are: void resize(?, int).
However the code compiles from command line.
How can I fix this fastidious behavior of eclipse?

After quite a while searching and tinkering with settings, I think I have found an answer. To get the indexer parsing the code correctly I had to:
Right click the project -> Properties
Go to C/C++ General -> Preprocessor Include Paths, Macros etc.
Click the providers tab
Check the CDT GCC Build-in Compiler Settings option
Apply
Rebuild index

Related

creating a define only used by eclipse

I have project that was created in another IDE that is build for a specific microcontroler. In the code faris used quite often and it is comprehended by the IDE and compiler.
I would like to use eclipse to edit the code, because it is more convinient to use. But it generates a lot of warnings and errors in the editor because he can not resolve the far.
I could create a macro #define far, but I would have to remove it when I want to compile the code. I don't compile with eclipse, because getting the compiler to work there is cumbersome and might introduce problems.
So is there a possibility that eclipse itself can handle the far for its syntax check?
Another approach that involves modifying your code rather than the project settings would be:
#ifdef __CDT_PARSER__
#define far
#endif
__CDT_PARSER__ is a macro that is automatically defined by CDT's parser when it processes your code, but not by any compiler.
After I searched a bit more I found an answer here:
https://www.eclipse.org/forums/index.php/t/72375/
Go to the menu:
Project -> Properties -> C/C++ General -> Path and Symbols ->
Symbols
and add a Symbol called far with the value /* */.
I just left the value empty and it worked.

Finding unused methods in scala using Intelli J

I am working on a scala project in IntelliJ and want to clean up my code.
For this, I am looking for a way in which I can get a list of unused methods within my project.
This link didn't answer my question. It is for Java and not for Scala.
Finding unused methods in IntelliJ (excluding tests)
Analyze -> Inspect Code for Scala in IntelliJ has an option to select unused symbol but I am unable to drill it down to only check methods.
Go to Analyze -> Inspect code
Under Inspection Profile click on "..." and make sure "Unused declaration" is checked. Chose Whole project option and then OK.

Eclipse C++ std::vector methods invalid parameters errors

I am working on an Android application that uses OpenCV 2.4.9 and NDKr9 as dependecies. I also use Eclipse 4.4 Luna as the IDE, with CDT plugin 8.4 installed.
Whenever I'm trying to use the methods std::vector.at(int), or the "[]" method, i get weird errors. For instance, consider the code:
#include <vector>
.........................
struct CustomStruct {
int level;
Point firstPoint, secondPoint, middlePoint;
};
.........................
int maxElemNr = 10;
std::vector<CustomStruct > customStructVector(maxElemNr);
.........................
for(int i=0;i<customStructVector.size();i++){
if(customStructVector.at(i).level == 0){
}
}
At customStructVector.at(i) Eclipse tells me the following:
Invalid arguments ' Candidates are: ResultWithEvidence & at(?) const
ResultWithEvidence & at(?)'
If I want to use the "[]" operator, instead of the "at(index)" method, i get the following:
resultWithEvidenceVector[i].level tells me that the field level is not found.
I am by no means an expert C/C++ coder, and I am rather new at working with the NDK. Coming from a Java background, I was expecting to get an object of type CustomStruct when calling either customStructVector.at(i) or customStructVector[i], such that I could then simply access the field level on my object, to read its value.
Also, declaring my vector as
int maxElemNr = 10;
std::vector<CustomStruct> customStructVector;
customStructVector.reserve(maxElemNr);
I get:
Invalid arguments ' Candidates are: void reserve(?) '
I have searched for answers, and came with the theory that eclipse might not use the c++11 version of the std library?
I've read about the vector class from here. Also, this issue closely resembles the question asked here.
Will provide more info about my environment and such, if needed. Would like to solve this, as it's quite a blocker for my project as of now..
What am I doing wrong? I had no problems compiling and running the code previously to using the std::vector class.
LE: apparently the workaround &(resultWithEvidenceVector.data()+i)->level is recognized by the editor, and the code compiles. Would still like to use the std::vector as it is supposed to be used though.
I had the same problem. It works in Visual Studio compiler but when i try to access vector element i get exactly the same error.
However it seems that if you don't use 'at' then it works for example customStructVector.at(i) use customStructVector(i),
It is strange. I didn't test it in detail. Please note that if you have vector you have to cast the result in order to access the type members.
Regards

Eclipse CDT methods comments autogeneration using Doxygen style

Hope this is not a duplicate... It should not since I tried the usual provided fixes.
I'm facing problems with the automated generation of comments for Classes and Methods using Elipse CDT (Juno/3.8, Linux) configured with Doxygen as default Documentation Tool.
I still get empty comments area for methods parameters while typing /** + ENTER :
/**
*
*/
Here is what I already tried without success :
Setting : Windows > Preferences > C/C++ > Editor > Documentation Tool Comments > Doxygen
Setting : Project > Preferences > Enable Project Specific Settings > Doxygen
Both lead to the same result.
Note : not sure about what happened with Eclipse configuration (it used to work fine before). Is that possible that I erased the Doxygen presets (maybe by pressing Windows > Preferences > C/C++ > Code Style > Code Templates > Restore Defaults). In that case how to get it back to Doxygen style ?
EDIT: I've got some new on the subject...
Basically, it was a global change in my project (which actually is a shared library). For some cross-platform portability reasons, I had to add a MACRO before all my classes, like follows :
class LIB_CLASS LabOneOfMyClasses {
public:
...
}
Unfortunately, doing this seems to break CDT's ability to generate smart functions headers (#param, #return, ...). So removing temporarily the MACRO, allows to get ride of this disagreeable behavior. It is annoying and is something I should report to CDT's staff...
Note : In the end, it is handled properly in Doxygen, anyway.
If someone has a brilliant idea, something I missed, about that ?
You can create a compiler abstraction header to solve this issue. Define a custom symbol in eclipse for your build configuration. Go to Project > Properties > C/C++ General > Paths and Symbols > Symbols > GNU C/C++ in eclipse and define a new unique symbol like #__ECLIPSE_CDT__.
Than in the compiler abstraction header you can write the followings:
#ifdef __ECLIPSE_CDT__
# define LIB_CLASS
#else
# define LIB_CLASS <required normal content>
#endif
And if you consistently include this compiler abstraction header into your files than eclipse will expand LIB_CLASS to nothing while your compiler will find and use the proper definition.

Eclipse CDT: how to add support for new filetype

In Eclipse CDT, I would like to create syntax highlighting and a error parser for a custom filetype, lets say *.xy.
Those files do not contain C-Code, so i cannot use any existing parsers.
What kind of plugins would I have to create?
For the error parser, I think I have to use Codan? (have not tried it yet)
https://www.ibm.com/developerworks/java/library/j-codan/
The CDT is the wrong start for your journey, if your language is not related to the CDT supported languages and workflows. Implement an xtext based language editor instead.
Maybe this is a simple solution for you:
colorEditor plugin
You can simply add a new language by unpacking the jar archive, then adding a xyz.xml file for your .xyz files.
Pakc together again, and copy into your Eclipse "plugins" dir.
You need to introduce a new "language" - this is the extension point: http://help.eclipse.org/helios/topic/org.eclipse.cdt.doc.isv/reference/extension-points/org_eclipse_cdt_core_language.html
Codan is not an "error parser" it is a static analysis framework. Error parser processes output of the command-line tools you use to build the application (e.g. compiler, linker) to identify errors that happened during the build and filling their attributes, e.g. source file name and line number.
Codan analyzes the source code in the editor to identify errors. E.g. it checks if the variable used in the expression was declared beforehand. Note that same check can be performed by a compile at a build time and then captured by error parser and shown in the editor/problems view - the goal of Codan is to detect problems sooner, before the build is even ran. Codan can also perform some checks that compiler doesn't.