Eclipse CDT indexing and std::unique_ptr

不问归期 提交于 2019-12-04 04:39:39

It seems as if the Eclipse CDT indexer is not able to deduce the unique_ptr::pointer type that is also used as the return type of operator->(). You can see this when you type something like

std::unique_ptr<Type *> ptr;
ptr.reset(new Type);

an error will be "detected" that there would be no matching overload, and that the only candidate would be reset(?). So this is obviously a bug.

This issue has been recently fixed, in cdt 8.1.1. Just go help->check for updates and it will be downloaded and installed. I've tested unique_ptr and it is properly indexed.

I have the same issue on newer version of Eclipse CDT (9.3). I tried all the tricks I found on the internet, rebuilding every time my index, hoping for a change. But the indexer was never able to deduce the type of std::unique_ptr<T>::operator->(). Finally, I decided to use a very simple workaround:

# ifdef ECLIPSE_INDEXER_WORKAROUND
MyType* my_var;
# else
std::unique_ptr<MyType> my_var;
# endif    

I add ECLIPSE_INDEXER_WORKAROUND to preprocessor symbols (of course for indexing options only, not building) in Eclipse, and indexing is useful again!

In order to pollute the code less, we can use a macro:

# ifdef ECLIPSE_INDEXER_WORKAROUND
#  define MY_UNIQUE_PTR( type ) type* 
# else
#  define MY_UNIQUE_PTR( type ) std::unique_ptr< type >
# endif

MY_UNIQUE_PTR( int ) pint{ new int(42) };
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!