microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Intellisense reports 'namespace "std" has no member' on Linux/clang-18/libc++

travbid opened this issue · comments

Environment

  • OS and Version: Ubuntu 22.04
  • VS Code Version: 1.89.1
  • C/C++ Extension Version: v1.20.5

Bug Summary and Steps to Reproduce

Bug Summary:

When using clang-18 with libc++ on Ubuntu, Intellisense erroneously reports namespace "std" has no member for some items.
Screenshot from 2024-05-21 22-40-34

Compiling from the command line with the same command from compile_commands.json succeeds, so it is not (directly) an error with clang.

Reproduction case: https://github.com/travbid/vscode-issue-repro/blob/master/main.cpp

Steps to reproduce:

  1. Install clang++-18 on Ubuntu as directed here: https://apt.llvm.org/
  2. Add the compile flag -stdlib=libc++ to the build
  3. Generate a compile_commands.json and set its path in c_cpp_properties.json. (In the above reproduction link, you can replace /home/travers/Projects in compile_commands.json to paths that are valid on your machine)
  4. Depending on the order of includes, some std members can't be found, e.g.
#include <chrono>
#include <span>
using std::span;

Expected behavior:

No red squiggles

Configuration and Logs

c_cpp_properties.json
log_diagnostics.txt
language_server.log

Other Extensions

No response

Additional context

The issue appears to be related to size_t not being defined in some cases, which in turn appears to be related to __building_module (a clang built-in?) not being defined in /usr/lib/llvm-18/lib/clang/18/include/__stddef_size_t.h:
Screenshot from 2024-05-21 23-16-34
Screenshot from 2024-05-21 23-18-57

Building from command line builds successfully:

travers:~/Projects/vscode-repro/build$ /usr/bin/clang++-18 -std=c++23 -stdlib=libc++ -o CMakeFiles/main.dir/main.cpp.o -c /home/travers/Projects/vscode-repro/main.cpp --verbose
Ubuntu clang version 18.1.6 (++20240518023229+1118c2e05e67-1~exp1~20240518143321.130)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/11
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12
Candidate multilib: .;@m64
Selected multilib: .;@m64
Found CUDA installation: /usr/local/cuda, version 12.2
 (in-process)
 "/usr/lib/llvm-18/bin/clang" -cc1 -triple x86_64-pc-linux-gnu -emit-obj -mrelax-all -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name main.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/home/travers/Projects/vscode-repro/build -v -fcoverage-compilation-dir=/home/travers/Projects/vscode-repro/build -resource-dir /usr/lib/llvm-18/lib/clang/18 -internal-isystem /usr/lib/llvm-18/bin/../include/c++/v1 -internal-isystem /usr/lib/llvm-18/lib/clang/18/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -std=c++23 -fdeprecated-macro -ferror-limit 19 -fgnuc-version=4.2.1 -fno-implicit-modules -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o CMakeFiles/main.dir/main.cpp.o -x c++ /home/travers/Projects/vscode-repro/main.cpp
clang -cc1 version 18.1.6 based upon LLVM 18.1.6 default target x86_64-pc-linux-gnu
ignoring nonexistent directory "/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include"
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/llvm-18/bin/../include/c++/v1
 /usr/lib/llvm-18/lib/clang/18/include
 /usr/local/include
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
travers:~/Projects/vscode-repro/build$ 

Thank you for sharing your repro steps, we will let you know if we need more information on the issue.