Skip to content
This repository has been archived by the owner on Jul 30, 2020. It is now read-only.
Fangrui Song edited this page Jan 20, 2018 · 33 revisions

Some C++ STL things are not recognized

There are at least three sets of implicit include paths. They take effect without your -I option in .cquery or compile_commands.json

// system C header, usually in /usr/include
#include <stdio.h>
// system C++ header. The location varies among distributions, e.g. /usr/include/c++/{6,7.2.1}
#include <new>
// In Clang resource directory
#include <stddef.h>

system C/C++ headers can be detected reliably. For Clang resource directory, there is logic in wscript to detect it when you run ./waf configure [OPTIONS]

  • For --bundled-clang=5.0.1: ../lib/clang+llvm-5.0.1-x86_64-linux-gnu-ubuntu-14.04/lib/clang/5.0.1 which is relative to the build/release/bin/cquery executable. The relative path of build/release/bin/cquery and build/release/lib/ cannot change, otherwise libclang.so used by cquery cannot find the Clang resource directory.
  • For --use-system-clang: it is recognized from -resource-dir option in the output of clang++ '-###' -xc /dev/null)
./waf configure --prefix /tmp/opt && ./waf install

If you want the cquery binary at a specific location use a symlink - do not move the binary itself.

Definitions

textDocument/definition can be used in many places. Some are current implementation details and may subject to change.

  • void foo(); Function definition and declaration jumps to each other
  • A a; Both the type and the variable jumps to the declaration/definition of A
  • a.field jumps to the member in the struct declaration
  • #include <map> jumps to the header
  • std::string a = "a"; takes you to the constructor. Many implicit constructors can also be jumped in this way.
  • a == b operator== for user defined operators

References

  • #include <iostream> lists all #include lines in the project pointing to the included file
  • {} lists all(?) lambda expressions thanks to implicit std::function move constructor