Search code examples
c++clangclionclang++

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


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:

enter image description here

enter image description here

However, with 4.0.1, everything works fine:

enter image description here

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.


Solution

  • 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.