cpptools insiders (0.29.0) Segmentation fault (With simple reproduction code) - std::rotate, C++20, Linux, Clang
Type: LanguageService
- OS and Version: Linux x64
- VS Code Version: 1.47.0-insiders
- C/C++ Extension Version: 0.29.0-insiders
cpptools-srv crashes instantly after typing C++ code below (C++20 mode):
#include <vector>
#include <iostream>
#include <algorithm>
int main()
{
std::vector<int> v{2, 4, 2, 0, 5, 10, 7, 3, 7, 1};
std::cout << "before sort: ";
for (int n: v)
std::cout << n << ' ';
std::cout << '\n';
// insertion sort
for (auto i = v.begin(); i != v.end(); ++i) {
std::rotate(std::upper_bound(v.begin(), i, *i), i, i+1);
}
std::cout << "after sort: ";
for (int n: v)
std::cout << n << ' ';
std::cout << '\n';
// simple rotation to the left
std::rotate(v.begin(), v.begin() + 1, v.end());
std::cout << "simple rotate left : ";
for (int n: v)
std::cout << n << ' ';
std::cout << '\n';
// simple rotation to the right
std::rotate(v.rbegin(), v.rbegin() + 1, v.rend());
std::cout << "simple rotate right : ";
for (int n: v)
std::cout << n << ' ';
std::cout << '\n';
}
(example code from cppreference.com): https://en.cppreference.com/w/cpp/algorithm/rotate
Steps to reproduce
- Copy example code from https://en.cppreference.com/w/cpp/algorithm/rotate at the bottom
- Run intellisense (Enable C++20 in .vscode/c_cpp_properties.json)
- Segmentation fault.
Logs from the command `C/C++: Log Diagnostics
-------- Diagnostics - 06/07/2020, 14:24:20
Version: 0.29.0-insiders
Current Configuration:
{
"name": "Linux",
"includePath": [],
"cppStandard": "c++20",
"compilerArgs": [],
"cStandard": "c11",
"intelliSenseMode": "gcc-x64",
"browse": {
"path": [
"${workspaceFolder}"
],
"limitSymbolsToIncludedHeaders": true
}
}
Translation Unit Mappings:
[ /home/XXXXXX/Desktop/repro/main.cpp ]:
/home/XXXXXX/Desktop/repro/main.cpp
Translation Unit Configurations:
[ /home/XXXXXX/Desktop/repro/main.cpp ]: not ready
Process ID: 33716
Memory Usage: 0 MB
Compiler Path: /usr/bin/clang
Includes:
/usr/include/c++/10.1.0
/usr/include/c++/10.1.0/x86_64-pc-linux-gnu
/usr/include/c++/10.1.0/backward
/usr/local/include
/usr/lib/clang/10.0.0/include
/include
/usr/include
Standard Version: c++20
IntelliSense Mode: clang-x64
Other Flags:
--clang
--clang_version=100000
Total Memory Usage: 0 MB
Logs from the language server:
sending compilation args for /home/XXXXX/Desktop/repro/main.cpp
include: /usr/include/c++/10.1.0
include: /usr/include/c++/10.1.0/x86_64-pc-linux-gnu
include: /usr/include/c++/10.1.0/backward
include: /usr/local/include
include: /usr/lib/clang/10.0.0/include
include: /include
include: /usr/include
define: __llvm__=1
define: __clang__=1
.........a lot of defines..........
other: --clang
other: --clang_version=100000
stdver: c++20
intelliSenseMode: clang-x64
Checking for syntax errors: file:///home/XXXXXX/Desktop/repro/main.cpp
Queueing IntelliSense update for files in translation unit of: /home/XXXXXX/Desktop/repro/main.cpp
cpptools/getDocumentSymbols: file:///home/XXXXXX/Desktop/repro/main.cpp (id: 4)
Processing folder (recursive): /usr/local/include/
Processing folder (recursive): /usr/lib/clang/10.0.0/include/
Processing folder (recursive): /include/
Processing folder (recursive): /usr/include/
cpptools/getFoldingRanges: file:///home/XXXXXX/Desktop/repro/main.cpp (id: 5)
cpptools/getDocumentSymbols: file:///home/XXXXXX/Desktop/repro/main.cpp (id: 6)
cpptools/abortRequest
cpptools/getDocumentSymbols
cpptools/getDocumentSymbols
cpptools/getFoldingRanges: file:///home/XXXXXX/Desktop/repro/main.cpp (id: 7)
cpptools/fileCreated: file:///home/XXXXXX/.config/Code%20-%20Insiders/logs/20200706T142658/sharedprocess.log
cpptools/fileCreated: file:///home/XXXXXX/.config/Code%20-%20Insiders/logs/20200706T142658/telemetry.log
cpptools/fileCreated: file:///home/XXXXXX/.config/Code%20-%20Insiders/logs/20200706T142658/userDataSync.log
Failed to read response from server: 22
(crash)
A workaround appears to be to set C_Cpp.intelliSenseCacheSize to 0. Let me know if that doesn't work for you.
Simplified repro is
#include <algorithm>
int main()
{
int v[3] = { 0, 1, 2 };
std::rotate(std::begin(v), std::begin(v) + 1, std::end(v));
}
Works perfectly without PCH/cache :)
I mistakenly thought the bug didn't repro with VS, but Colen discovered that it did. I've filed bug https://developercommunity.visualstudio.com/content/problem/1109849/cc-intellisense-process-crashes-when-stdrotate-is.html .
Should be fixed with https://github.com/microsoft/vscode-cpptools/releases/tag/0.30.0-insiders