std::string treated as int
Under Ubuntu 16.04, Visual Studio Code 1.27.2, cquery extension 0.1.10.
Consider such code:
std::string msg;
msg += '+';
msg += '?';
For the third line I get:
[cquery] incompatible pointer to integer conversion assigning to 'std::string' (aka 'int') from 'const char *' [-Wint-conversion]
Why the heck is std::string treated as int by cquery?
This usually means that the flags you supplied to cquery aren't correct for your project, so clang fails to correctly instantiate std::string. This isn't so uncommon in template heavy code when given wrong flags.
Sorry, for closing/reopening - my browser is broken and I can't see the buttons on the page.
I generate compile_commands.json using cmake and create a symbolic link to the file in the root directory. Maybe the problem is that the I mix C and C++ code?
Maybe, but we can only guess with absolutely no debugging information provided so far. What are you flags exactly? What is the content of the cquery's log? What code shows the issue? We need a minimal repro case if you want us to figure out what's wrong with your flags.
Ok. Thanks, @bstaletic for the suggestion about the compilation database. I compile using arm-none-eabi toolchain for STM32 chip series. A single entry for the erroneous C++ file look like that:
{
"directory": "/firmware/build",
"command": "/toolchain/bin/arm-none-eabi-g++ -DCROSS_COMPILING -DSTM32L4 -DSTM32L432xx -DUSE_FULL_LL_DRIVER -DUSE_HAL_DRIVER -I/firmware/Inc -I/firmware/Drivers/CMSIS/Device/ST/STM32L4xx/Include -I/firmware/Drivers/CMSIS/Include -I/firmware/Middlewares/Third_Party/FreeRTOS/Source/include -I/firmware/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS -I/firmware/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F -I/firmware/Drivers/STM32L4xx_HAL_Driver/Inc -I/firmware/app/fw/tinyprintf -I/firmware/app -I/firmware/app/fw -I/firmware/app/rtos/inc -I/firmware/app/hwaccess/inc -I/firmware/app/fw/inc -I/firmware/app/fw/data_structs -mthumb -fno-builtin -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -Wall -std=c++14 -ffunction-sections -fdata-sections -fomit-frame-pointer -mabi=aapcs -fno-unroll-loops -ffast-math -ftree-vectorize -Og -g -o CMakeFiles/AgriWatch.dir/app/rtos/src/at.cpp.obj -c /firmware/app/rtos/src/at.cpp",
"file": "/firmware/app/rtos/src/at.cpp"
}
The cquery's log is:
[cquery] incompatible pointer to integer conversion assigning to 'std::string' (aka 'int') from 'const char *' [-Wint-conversion]
I inspected the flags and experimentally removed single flags one by one to check when the problem arises. When I remove the flags: -DCROSS_COMPILING -DSTM32L4 -DSTM32L432xx -DUSE_FULL_LL_DRIVER -DUSE_HAL_DRIVER (so all the definition flags) from commands then cquery doesn't complain. Those flags are defined using ADD_DEFINITIONS cmake command. Those flags don't affect the erroneous file (they aren't used inside it).