CLion 2017.3 unable to autocomplete through unique_ptr using clang 5 (works with 4.0.1)

妖精的绣舞 提交于 2020-05-14 12:33:49

问题


edit: scroll to bold section below for current status.

CLion seems to be unable to autocomplete members of a type pointed to by a unique_ptr in clang 5. I either get "no suggestions" or I get suggestions for member functions on the unique_ptr itself:

However, with 4.0.1, everything works fine:

I also noticed that if I ask CLion to jump to the definition of the -> on c->, in 4.0.1 it finds it:

    _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT {return __ptr_.first();}

But in 5.0.0, the same command says: Cannot find declaration to go to, so that seems to be closer to the root of the problem.

shared_ptr-><AUTOCOMPLETE> works fine in both versions.

Simplifying the code in <memory> for unique_ptr::operator->'s return type to element_type * fixes the problem, but changing core include files isn't something I love doing. Confusingly, that part of the code in 5.0 is the same as it is in 4.0.1 where it works fine.

  _LIBCPP_INLINE_VISIBILITY
  element_type * operator->() const _NOEXCEPT {
      return __ptr_.first();
  }  _LIBCPP_INLINE_VISIBILITY

    // original code that doesn't play nice with CLion
//    pointer operator->() const _NOEXCEPT {
//        return __ptr_.first();
//    }

I'm interested in any workarounds or even just an explanation as to what is going on to cause this.

I'm on a Mac pre-built binaries from the llvm download site. I'm wondering if it's an issue with the Apple clang numbering scheme vs the real clang version numbers. Maybe the clang analyzer thinks I'm on some ancient version of (apple) clang instead of modern "real" clang.

Thank you.


回答1:


A workaround is to change the return type of unique_ptr::operator-> in the memory header.

  _LIBCPP_INLINE_VISIBILITY
  element_type * operator->() const _NOEXCEPT {
      return __ptr_.first();
  }  _LIBCPP_INLINE_VISIBILITY

    // original code that doesn't play nice with CLion
//    pointer operator->() const _NOEXCEPT {
//        return __ptr_.first();
//    }

Makes things work and more closely mirrors how things are done in shared_ptr, which works out of the box.




回答2:


I want to follow up here that the above (accepted) solution works with the libstdc++ implementation of unique_ptr as well, at least the one that came with GCC 8.1 that I am using.

Another solution, for reasons I detailed here, is that you can add a using directive at the beginning of the structure like using pointer = C*. This fools Netbeans into auto-completing properly without warnings. This solution may be specific to libstdc++, but based on your answer, it looks like libc++ internally uses the same typename for the pointer.



来源:https://stackoverflow.com/questions/48617011/clion-2017-3-unable-to-autocomplete-through-unique-ptr-using-clang-5-works-with

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