clang code-completion

Status
Not open for further replies.

cburn11

Ars Praetorian
447
Subscriptor
I am running into a problem with clang's code-completion feature.

A simple class illustrates the problem:
~/Source/clang-test/test.h:
Code:
#include <string>
#include <utility>
class Full_Name {

  std::string m_firstName;
  std::string m_lastName;

  std::string m_fullName;

public:

  Full_Name(std::string firstName, std::string lastName) :
    m_firstName(std::move(firstName)),
    m_lastName(std::move(lastName)) {

      m_fullName = m_firstName + " " + m_lastName;
}

  std::string to_string() const { return m_ }
};

Asking clang for completion suggestions at "m_" in the to_string method;
Code:
clifford@Google-VM:~/Source$ clang -std=c++11 -fsyntax-only -x c++   -Xclang -code-completion-at=clang-test/test.h:15:43 clang-test/test.h

generates the error:
Code:
};
^
clang-test/test.h:3:17: note: to match this '{'
 class Full_Name {
            ^
clang-test/test.h:14:42: error: use of undeclared identifier 'm'
 std::string to_string() const { return m<U+0000>_ }
                                     ^
clang-test/test.h:14:43: error: expected '}'
 std::string to_string() const { return m<U+0000>_ }
                                      ^
clang-test/test.h:14:33: note: to match this '{'
 std::string to_string() const { return m<U+0000>_ }
                            ^
clang-test/test.h:14:43: error: expected ';' after class
 std::string to_string() const { return m<U+0000>_ }
                                      ^
                                      ;
4 errors generated.

But if I move the method definition out of the class definition:

Code:
#include <string>
#include <utility>
class Full_Name {

  std::string m_firstName;
  std::string m_lastName;

  std::string m_fullName;

public:

  Full_Name(std::string firstName, std::string lastName) :
    m_firstName(std::move(firstName)),
    m_lastName(std::move(lastName)) {

      m_fullName = m_firstName + " " + m_lastName;
}

  std::string to_string() const;
};

std::string Full_Name::to_string() const { 
return m_ 
}

Asking for code-completion suggestions at "m_" of the to_string method:
Code:
clifford@Google-VM:~/Source$ clang -std=c++11 -fsyntax-only -x c++ -Xclang -code-completion-at=clang-test/test.h:22:10 clang-test/test.h

generates the expected results:
Code:
COMPLETION: m_firstName : [#std::string#]m_firstName
COMPLETION: m_fullName : [#std::string#]m_fullName
COMPLETION: m_lastName : [#std::string#]m_lastName

Oddly enough even when the method definition is within the class definition, if I as clang for suggestions after "this->", clang returns the expected suggestions:

Code:
COMPLETION: Full_Name : Full_Name::
COMPLETION: m_firstName : [#std::string#]m_firstName
COMPLETION: m_fullName : [#std::string#]m_fullName
COMPLETION: m_lastName : [#std::string#]m_lastName
COMPLETION: to_string : [#std::string#]to_string()[# const#]

If anyone has any experience clang's code-completion, is the command line I am using to call clang wrong?
 

cburn11

Ars Praetorian
447
Subscriptor
Fair enough.

I am running clang 5.0:
Code:
clifford@Google-VM:~$ clang --version
clang version 5.0.0-3 (tags/RELEASE_500/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

On artful (headless, I am SSHd in):
Code:
clifford@Google-VM:~$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 17.10
Release:	17.10
Codename:	artful

with, what I assume to be the latest version of, 4.13:
Code:
clifford@Google-VM:~$ uname -a
Linux Google-VM 4.13.0-25-generic #29-Ubuntu SMP Mon Jan 8 21:14:41 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

on an AMD cpu:
Code:
clifford@Google-VM:~$ lscpu
Architecture:        x86_64
CPU op-mode(s):      32-bit, 64-bit
Byte Order:          Little Endian
CPU(s):              16
On-line CPU(s) list: 0-15
Thread(s) per core:  2
Core(s) per socket:  8
Socket(s):           1
NUMA node(s):        1
Vendor ID:           AuthenticAMD
CPU family:          23
Model:               1
Model name:          AMD Ryzen 7 1800X Eight-Core Processor
Stepping:            1
CPU MHz:             2200.000
CPU max MHz:         3600.0000
CPU min MHz:         2200.0000
BogoMIPS:            7186.05
Virtualization:      AMD-V
L1d cache:           32K
L1i cache:           64K
L2 cache:            512K
L3 cache:            8192K
NUMA node0 CPU(s):   0-15
Flags:               fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb
rdtscp lm constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid aperfmperf pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 movbe popcnt aes xsave avx f
16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_ll
c mwaitx cpb hw_pstate sme vmmcall fsgsbase bmi1 avx2 smep bmi2 rdseed adx smap clflushopt sha_ni xsaveopt xsavec xgetbv1 xsaves clzero irperf arat npt lbrv
svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif overflow_recov succor smca

The text editor I am using is emacs, the latest from the artful repository:
Code:
clifford@Google-VM:~$ emacs --version
GNU Emacs 25.2.2
Copyright (C) 2017 Free Software Foundation, Inc.
GNU Emacs comes with ABSOLUTELY NO WARRANTY.
You may redistribute copies of GNU Emacs
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING.

And the encoding of test.h is utf-8-unix. I originally thought the encoding might be the issue since the clang error messages contained "<U+0000>". But other 8 bit encoding produces the same error. And clang rejects test.h entirely with a 16 bit encoding.
 
Status
Not open for further replies.