I use Eclipse CDT for a C project. I only use the editor as the build environment is outside of Eclipse.
Error markers in the code are shwon as expected with a few exceptions:
When I make a function call it does not matter if the function exists or not. The editor will never show an error marker on the function call. I would expect an "Unresolved symbol" error, or similar. I would expect misspelled function names to show up as error, and I would expect existing functions that are declared in header files that I forgot to include to show up as errors. But this is not the case.
When I enter the name of an enum member that does exist somewhere else (in a header file) in the project, then the editor recognizes it even if I do not include the header file where it is included. This will of course lead to a compiler error, but I would expect an error marker in the editor.
Is there some setting I am missing? Or is this just the way the eclipse editor works?
I have a faint memory of seeing those error markers long time ago, but memory may play tricks on me...
Resolving names whose definitions are in the project but not reachable through includes, is a known issue. It's tracked by bug 297690, and it's close to being fixed (with most of the hard work being done in bug 402498).
Resolving the name of a function which is not in the project at all, can happen in two situations.
In C code
The C language does not require that functions be declared prior to their use. A use without a preceding declaration is treated as an implicit declaration.
That is, the following C file is valid code:
void func() {
another_func(); // another_func is implicitly declared here
}
The linker will try to find a matching function definition at link time, and give an error if it cannot.
So, if you misspell another_func
, the error will not be caught at compilation time (only at linking time), and similarly CDT cannot diagnose it.
In C++ template code
Unlike C, C++ does require that functions be declared prior to their use. However, there is one subtlety involving templates.
If a function call occurs inside a template and some of the arguments are dependent:
template <typename T>
void foo(T t) {
misspelt_function(t);
}
CDT can't diagnose the misspelt function at the point of foo
's definition because of the way C++'s two-phase name lookup rules work: it would be valid to provide a definition of misspelt_function
after the point of foo
's definition (but before the point of instantiation) that's found by argument-dependent lookup (by being in a namespace associated with the type of t
for this particular instantiation).
(CDT could in theory diagnose the misspelt function for particular instantiations of foo
, the way a compiler does, but it currently doesn't type-check the bodies of instantiations at all.)