Type: LanguageService
Definitions from compile_commands.json gets parsed wrong. If I want to pass definition via CMake I add following statement in CMakeLists.txt:
add_definitions("-D__weak=__attribute__((weak))" -DABC=\"asd\")
Now __weak should be replaced with __attribute__((weak)) in code, and ABC should be replaced with "asd" string literal. At least that how compiler behaves. Instead if I hover over __weak i get #define __weak "__attribute__((weak))" which is incorrect. Also if i hover over ABC i get proper information #define ABC "asd". This happens only when definition contains one or more characters that have to be escaped, so if I set __weak definition to __attribute__ it gets passed correctly. It happens because without need to escape characters, part after = in definition does not get wrapped in " by CMake. So instead -D__weak="__attribute__((weak))" on command line appears -D__weak=__attribute__.
This also causes problem to be reported (but it is due to invalid __weak value):
{
"resource": "vscode-intelisense/lib.cxx",
"owner": "_generated_diagnostic_collection_name_#0",
"code": "undefined",
"severity": 8,
"message": "expected a declaration",
"startLineNumber": 1,
"startColumn": 1,
"endLineNumber": 1,
"endColumn": 2
}
- OS and Version:
Linux 4.17.6-1-ARCH
- VS Code Version:
1.25.1
- C/C++ Extension Version:
0.17.7
- Clang Version:
6.0.1
To Reproduce
Example:
c_cpp_properties.json
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64",
"compileCommands": "${workspaceFolder}/build/compile_commands.json"
}
],
"version": 4
}
lib.cxx
CMakeLists.txt
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(vscode-intelisense)
set(CMAKE_EXPORT_COMPILE_COMMANDS "1")
set(CMAKE_CXX_STANDARD 17)
add_library(${PROJECT_NAME} STATIC lib.cxx)
add_definitions("-D__weak=__attribute__((weak))" -DABC=\"asd\")
Steps to reproduce the behavior:
- Recreate file structure:
vscode-intelisense
|
|-lib.cxx
|-CMakeLists.txt
.vscode
|-c_cpp_properties.json
- Build with
rm -rf build && cmake . -Bbuild && VERBOSE=1 cmake --build build inside vscode-intelisense folder.
- Open
vscode-intelisense directory in vscode.
- Hover over
__weak and ABC in lib.cxx.
Expected behavior
__weak definition to be recognized correctly as __attribute__((weak)) instead "__attribute__((weak))".
No problems reported.
Type: LanguageService
Definitions from
compile_commands.jsongets parsed wrong. If I want to pass definition via CMake I add following statement inCMakeLists.txt:Now
__weakshould be replaced with__attribute__((weak))in code, andABCshould be replaced with"asd"string literal. At least that how compiler behaves. Instead if I hover over__weaki get#define __weak "__attribute__((weak))"which is incorrect. Also if i hover overABCi get proper information#define ABC "asd". This happens only when definition contains one or more characters that have to be escaped, so if I set__weakdefinition to__attribute__it gets passed correctly. It happens because without need to escape characters, part after=in definition does not get wrapped in"by CMake. So instead-D__weak="__attribute__((weak))"on command line appears-D__weak=__attribute__.This also causes problem to be reported (but it is due to invalid
__weakvalue):Linux 4.17.6-1-ARCH1.25.10.17.76.0.1To Reproduce
Example:
c_cpp_properties.jsonlib.cxxCMakeLists.txtSteps to reproduce the behavior:
rm -rf build && cmake . -Bbuild && VERBOSE=1 cmake --build buildinsidevscode-intelisensefolder.vscode-intelisensedirectory in vscode.__weakandABCinlib.cxx.Expected behavior
__weakdefinition to be recognized correctly as__attribute__((weak))instead"__attribute__((weak))".No problems reported.