The indexer of eclipse CDT does not properly recognize the 'end' and 'begin' symbols needed in a foreach loop whenever I want to directly iterate over data returned by a function. It works when I first put the result into a temporary variable.
MWE:
#include "mwe.h"
int main(int argc, char **argv) {
auto tmp = do_something();
for(auto &x : tmp){ } //Working
for(auto &x : do_something()){ } //Symbol 'end'/'begin' could not be resolved
}
mwe.h:
#include<iterator>
class X { };
class Handle { };
class MyIterator: public std::iterator<X, std::input_iterator_tag> {
public:
explicit MyIterator(Handle &iter) : iter_(&iter) { }
MyIterator() { }
MyIterator &operator++() { return *this; }
MyIterator operator++(int) { return *this; }
X &operator*() { return x; }
X *operator->() { return &**this; }
friend bool operator==(MyIterator a, MyIterator b) { return true; }
friend bool operator!=(MyIterator a, MyIterator b) { return false; }
private:
Handle *iter_;
X x;
};
inline MyIterator begin(Handle &it) { return MyIterator(it); }
inline MyIterator end(Handle &) { return MyIterator(); }
Handle do_something() { return Handle(); }
The code compiles and works with no errors, only the indexer tells me that it does not find the symbols. That said, fixing the problem is not really necessary but it is quite annoying.
Additional note: I already checked many other Questions regarding the Indexer in CDT but the answers didn't fix my problem:
Eclipse CDT Indexer does not fully recognize c++11
Eclipse CDT: Symbol 'cout' could not be resolved
https://www.eclipse.org/forums/index.php/t/636348/
Is there a problem with the code or is it a (known) bug in CDT?