Sarcasm / company-irony

company-mode completion back-end for irony-mode
119 stars 11 forks source link

Not completing protected members from parent class #22

Open cbourjau opened 8 years ago

cbourjau commented 8 years ago

Hello, I am using irony and its company-irony completion every day and I love it. However, today I noticed an issue with protected members. Everything works fine in the class itself, but the protected members are not available for auto-completion in the deriving classes. Public members work fine and flycheck is not showing an error either. Am I missing something here or is this unexpected behaviour? My configuration is as below and I am on Ubuntu 14.04 with clang-3.5.

Thanks, Christian

(use-package flycheck-irony
  :ensure t
  :config
  (eval-after-load 'flycheck
    '(add-hook 'flycheck-mode-hook #'flycheck-irony-setup))
  )
(use-package irony
  :ensure t
  :init
  (add-hook 'c++-mode-hook 'irony-mode)
  (add-hook 'c-mode-hook 'irony-mode)
  (add-hook 'objc-mode-hook 'irony-mode)
  :config
  ;; replace the `completion-at-point' and `complete-symbol' bindings in
  ;; irony-mode's buffers by irony-mode's function
  (defun my-irony-mode-hook ()
    (define-key irony-mode-map [remap completion-at-point]
      'irony-completion-at-point-async)
    (define-key irony-mode-map [remap complete-symbol]
      'irony-completion-at-point-async))
  (add-hook 'irony-mode-hook 'my-irony-mode-hook)
  (add-hook 'irony-mode-hook 'irony-cdb-autosetup-compile-options)
  ;;(eval-after-load 'flycheck
  ;;  '(add-hook 'flycheck-mode-hook #'flycheck-irony-setup))
  (eval-after-load 'company
    '(add-to-list 'company-backends 'company-irony))
  ;; (optional) adds CC special commands to `company-begin-commands' in order to
  ;; trigger completion at interesting places, such as after scope operator
  ;;     std::|
  (add-hook 'irony-mode-hook 'company-irony-setup-begin-commands)
  ;; standard is "clang-3.4" -> not present on ubuntu
  (setq company-clang-executable "clang-3.5")
  )
(use-package company
  :ensure t
  :init (add-hook 'after-init-hook 'global-company-mode)
  :config
  (use-package company-irony :ensure t :defer t)
  :bind ("C-;" . company-complete-common)
  )
Sarcasm commented 8 years ago

Minimal reproduction:

class Base
{
public:
  Base();

public:
  int m_public;
protected:
  int m_protected;
private:
  int m_private;
};

class Derived : public Base
{
  Derived()
  {
    this->|  // only provides m_public, not m_protected
  }
};

I can confirm your issue, if I comment the following check in Irony.cpp:

      if (availability == CXAvailability_NotAccessible ||
          availability == CXAvailability_NotAvailable) {
        continue;
      }

The bug seems to be in libclang, CXAvailability_NotAccessible removes the protected members. Howewer, removing this check also adds private members, not sure which is best. Ideally we should confirm that the issue is in libclang and report a bug/provide a patch.

Sarcasm commented 8 years ago

I look slightly more, this is a known bug: https://llvm.org/bugs/show_bug.cgi?id=24329

cbourjau commented 8 years ago

Many thanks for your effort! Unfortunately, it seems like that bug did not get a lot of traction since it was posted, but I fond some other reports as well. This one looked most promising: https://llvm.org/bugs/show_bug.cgi?id=20220