3

How to conf vscode-clangd to use c++11 for lint?

I added both complie_commands.json and complie_flags.txt in workshop.

workshop
|-complie_commands.json
|-complie_flags.txt
|-list.cpp

complie_commands.json

[
   { "directory": "pathto/workshop/",
     "command": "/opt/rh/llvm-toolset-7/root/usr/bin/clang++ -o file *cpp -std=c++11"}
]

compile_flags.txt

-std=c++11

It couldn't recognize auto with error:

'auto' type specifier is a C++11 extension
L.SG
  • 121
  • 1
  • 5

1 Answers1

2

Set cppStandard in c_cpp_properties.json to c++11. e.g.:

{
  "env": {
    "myDefaultIncludePath": ["${workspaceFolder}", "${workspaceFolder}/include"],
    "myCompilerPath": "/usr/local/bin/gcc-7"
  },
  "configurations": [
    {
      "name": "Linux",
      "intelliSenseMode": "clang-x64",
      "includePath": ["${myDefaultIncludePath}", "/another/path"],
      "macFrameworkPath": ["/System/Library/Frameworks"],
      "defines": ["FOO", "BAR=100"],
      "forcedInclude": ["${workspaceFolder}/include/config.h"],
      "compilerPath": "/usr/bin/clang",
      "cStandard": "c11",
      "cppStandard": "c++11",
      "compileCommands": "/path/to/compile_commands.json",
      "browse": {
        "path": ["${workspaceFolder}"],
        "limitSymbolsToIncludedHeaders": true,
        "databaseFilename": ""
      }
    }
  ],
  "version": 4
}
Alan Birtles
  • 32,622
  • 4
  • 31
  • 60