Incorrect red error squiggles from clangd with VSCode?

1,240 views
Skip to first unread message

James Cook

unread,
Jul 21, 2022, 1:57:15 PM7/21/22
to chromium-dev
Starting in the last couple days my teammates and I have noticed VSCode + clangd incorrectly flagging certain code as an error. Does anyone know what's wrong, or how to fix this?

Typical errors include confusion about subclasses:
"Cannot initialize a parameter of type 'views::View *' with an lvalue of type 'ash::AppListItemView *'clang(init_conversion_failed)"
(but AppListItemView is-a View)

and errors on absl::optional<>:
Builtin __has_trivial_destructor is deprecated; use __is_trivially_destructible instead clang(-Wdeprecated-builtins)
type_traits.h(99, 27): In instantiation of template class 'absl::is_trivially_destructible<int>' requested here

The code compiles fine with ninja. I'm on the ChromeOS team, so this is the target_os=chromeos build on gLinux. I'm on VSCode 1.69.2 on gLinux, with clangd version google3-trunk (32a425ec0c10ebb0b0cb9a0c1cdf101e62c1b43e). It happens both with and without --chrome-remote-index.

Thanks!
James

Nico Weber

unread,
Jul 21, 2022, 2:03:21 PM7/21/22
to James Cook, chromium-dev
Upstream clang marked these builtins deprecated. See https://bugs.chromium.org/p/chromium/issues/detail?id=1343975&q=__has_trivial_destructor&can=2 for details.

We haven't rolled in that upstream change yet, so the workaround is behind the `llvm_force_head_revision=true` gn arg.

The core problem here is that your clangd is out of sync with chromium's clang. That will often work, but not always.

If you can move to an older clangd binary, that'll work for now.

If there's a way to pass extra cflags to clangd, you can add -Wno-deprecated-builtins there.

This will fix itself the next time we update the compiler. https://crbug.com/1343804 tracks updating the compiler.

--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CAKLzqjEqsMKi58563nOF88S4jMdCftf9LcxPfZYqzkmsNyb%2BCw%40mail.gmail.com.

David Grogan

unread,
Jul 21, 2022, 2:33:23 PM7/21/22
to tha...@chromium.org, James Cook, chromium-dev
I hit this too. I ended up running `tools/clang/scripts/build_clang_tools_extra.py --fetch out/Default clangd` and setting clangd path in vscode. But if I'd known about passing extra cflags to clangd, I'd have just done that. Looks like https://clangd.llvm.org/config.html#compileflags is how to do it?

James Cook

unread,
Jul 21, 2022, 4:47:54 PM7/21/22
to David Grogan, Nico Weber, chromium-dev
Thanks for the advice! I added the following to my ~/.config/clangd/config.yaml file, which seems to have worked around the issue:

If:
  PathMatch: /usr/local/google/home/jamescook/chrome/src/.*
CompileFlags:
  Add: [-Wno-deprecated-builtins]

Thanks again,
James

David Grogan

unread,
Jul 22, 2022, 5:41:19 PM7/22/22
to Hao Liu, Chromium-dev, jame...@chromium.org, Nico Weber
`sudo apt install cmake` should be all you need to do.

But James's way is more future-proof. Try his way first.

On Fri, Jul 22, 2022 at 2:17 PM Hao Liu <hao...@google.com> wrote:
glad to find this thread.
I'm having the same problem.
I tried "tools/clang/scripts/build_clang_tools_extra.py --fetch out/Default clangd"
but got this error?
Does this mean I need to install cmake myself?
I work on a cloudtop that is glinux. Is there vetting in place for installing new softwares?
Thanks!

```
Updating files: 100% (5951/5951), done.
Previous HEAD position was ff1920d106b5 [NVPTX] Promote i24, i40, i48 and i56 to next power-of-two register when passing
HEAD is now at 89a99ec900d5 [GVN] Bug fix to reportMayClobberedLoad remark
Building targets: clangd
Traceback (most recent call last):
  File "/usr/local/google/home/haoliuk/chromium/src/tools/clang/scripts/build_clang_tools_extra.py", line 97, in <module>
    sys.exit(main())
  File "/usr/local/google/home/haoliuk/chromium/src/tools/clang/scripts/build_clang_tools_extra.py", line 93, in main
    BuildTargets(GetBuildDir(args.OUT_DIR), args.TARGETS)
  File "/usr/local/google/home/haoliuk/chromium/src/tools/clang/scripts/build_clang_tools_extra.py", line 73, in BuildTargets
    subprocess.check_call(cmake_args, cwd=build_dir)
  File "/usr/lib/python3.10/subprocess.py", line 364, in check_call
    retcode = call(*popenargs, **kwargs)
  File "/usr/lib/python3.10/subprocess.py", line 345, in call
    with Popen(*popenargs, **kwargs) as p:
  File "/usr/lib/python3.10/subprocess.py", line 966, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.10/subprocess.py", line 1842, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'cmake'

```

Hao Liu

unread,
Jul 29, 2022, 8:22:48 PM7/29/22
to Chromium-dev, jame...@chromium.org, Nico Weber, chromium-dev, David Grogan

Hao Liu

unread,
Jul 29, 2022, 8:23:12 PM7/29/22
to David Grogan, Chromium-dev, jame...@chromium.org, Nico Weber
Thanks!
I don't have that yaml file. 
If I create one, how to I point the clangd to that config.yaml?

Nico Weber

unread,
Aug 30, 2022, 3:19:18 PM8/30/22
to James Cook, chromium-dev
On Thu, Jul 21, 2022 at 2:02 PM Nico Weber <tha...@chromium.org> wrote:
Upstream clang marked these builtins deprecated. See https://bugs.chromium.org/p/chromium/issues/detail?id=1343975&q=__has_trivial_destructor&can=2 for details.

We haven't rolled in that upstream change yet, so the workaround is behind the `llvm_force_head_revision=true` gn arg.

The core problem here is that your clangd is out of sync with chromium's clang. That will often work, but not always.

It's now possible to use a clangd binary that's always in-sync with the compiler. https://chromium.googlesource.com/chromium/src/+/master/docs/clangd.md now documents how to do this.
Reply all
Reply to author
Forward
0 new messages