Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable completion of C++ template classes in vim using YouCompleteMe

When using the vim plugin YouCompleteMe for C++ code completion I stumbled over an issue. Using nested template classes stops the completion to work properly.

Consider the following example to reproduce the behaviour:

#include <vector>

template<class T>
class foo {
  public:
  void Init();

  private:
  struct bar {
    int foobar;
  };
  bar one_bar;
  std::vector<foo<T>::bar> some_bars;
};

template<class T>
void foo<T>::Init(){
  one_bar.foobar = 0; // completion as expected
  some_bars.at(0).foobar = 0; // no completion neither for "at" nor for "foobar"
}

The code completion for "some_bars" is not working at all while "one_bar" behaves as expected.

How can I get completion working for this code? Is this issue related to the setup and should actually work or is it a bug in YCM?

My system is debian jessie/sid based, vim version 7.4, YCM latest version from GitHub.

Edit: There are similar issues reported in YCMs bug tracker: https://github.com/Valloric/YouCompleteMe/issues/243 https://github.com/Valloric/YouCompleteMe/issues/530

Seems to be a bug in clang rather than in YCM. Can someone confirm this?

Edit2: I opened another issue in the YCM issue tracker. https://github.com/Valloric/YouCompleteMe/issues/1170

The intention is to get more information on what the bug in clang exactly is and finally to make a bug report in the clang issue tracker.

Edit3: I followed the proposed procedure from RedX and fed my code in clang to get completions. Clang does not provide any suggestions for the discussed positions in the code. This clearly is the reason why YCM fails to make suggestions in vim and it has nothing to do with YCM or vim.

A bug report in the clang issue tracker has been filed: http://llvm.org/bugs/show_bug.cgi?id=20973

like image 978
Phil Avatar asked Aug 15 '14 11:08

Phil


1 Answers

I think, under the rules of C++, you cannot get completion in this case.

Without knowledge of the type T, we don't know what methods std::vector<T> will have, as each instansiation of a template in C++ can have different methods.

like image 81
Chris Jefferson Avatar answered Nov 06 '22 15:11

Chris Jefferson