vscode-cpptools
vscode-cpptools copied to clipboard
`std::source_location::function_name` gets inconsistent results with GCC/Clang
Environment
- OS and Version: Linux 6.1.0-25-amd64; Debian GNU/Linux 12 (bookworm)
- VS Code Version: 1.93.1
- C/C++ Extension Version: v1.22.6 (pre-release)
- If using SSH remote, specify OS of remote machine: N/A
Bug Summary and Steps to Reproduce
Bug Summary:
In GCC/Clang, C++20 std::source_location::function_name
expands to __PRETTY_FUNCTION__
, that includes parameter type, template arguments and return type etc. But C/C++ extension just contains function name, i.e. __func__
.
Steps to reproduce:
- Configured to a C++20-ready GCC/Clang compiler;
- Enter following code
#include <source_location>
#include <string_view>
void foo(int) {
constexpr std::string_view function_name = std::source_location::current().function_name();
static_assert(function_name == std::string_view{__PRETTY_FUNCTION__});
static_assert(function_name != std::string_view{__func__});
}
Expected behavior:
All above static_assert
s should succeeded instead of failed. Godbolt
Configuration and Logs
c_cpp_properties.json
:
{
"version": 4,
"configurations": [
{
"name": "Linux",
"compilerPath": "/home/linuxbrew/.linuxbrew/bin/g++-14",
"cppStandard": "c++23"
}
]
}
C/C++ diagnostic logs:
-------- Diagnostics - 2024/9/29 14:58:23
Version: 1.22.6
Current Configuration:
{
"name": "Linux",
"compilerPath": "/home/linuxbrew/.linuxbrew/bin/g++-14",
"cppStandard": "c++23",
"compilerPathIsExplicit": true,
"cStandardIsExplicit": true,
"cppStandardIsExplicit": true,
"intelliSenseModeIsExplicit": false,
"compilerPathInCppPropertiesJson": "/home/linuxbrew/.linuxbrew/bin/g++-14",
"cStandard": "c17",
"mergeConfigurations": false,
"browse": {
"path": [
"${workspaceFolder}"
],
"limitSymbolsToIncludedHeaders": true
}
}
Modified Settings:
{
"C_Cpp.default.compilerPath": "/home/linuxbrew/.linuxbrew/bin/g++-14",
"C_Cpp.default.cStandard": "c17",
"C_Cpp.default.cppStandard": "c++23",
"C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: Google, AccessModifierOffset: -2, IndentWidth: 2, TabWidth: 2, ColumnLimit: 80, PointerAlignment: Left, AllowShortFunctionsOnASingleLine: Empty, AllowShortCaseLabelsOnASingleLine: true, AllowShortIfStatementsOnASingleLine: WithoutElse, AllowAllArgumentsOnNextLine: true }"
}
Additional Tracked Settings:
{
"editorTabSize": 2,
"editorInsertSpaces": true,
"editorAutoClosingBrackets": "languageDefined",
"filesEncoding": "utf8",
"filesAssociations": {
"*.bf": "brainfuck",
"*.itexi": "texinfo",
"*.json5": "jsonc",
"string_view": "cpp"
},
"filesExclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"**/Thumbs.db": true,
"**/*.dSYM": true
},
"filesAutoSaveAfterDelay": false,
"editorInlayHintsEnabled": true,
"editorParameterHintsEnabled": true,
"searchExclude": {
"**/node_modules": true,
"**/bower_components": true,
"**/*.code-search": true
},
"workbenchSettingsEditor": "ui"
}
cpptools version (native): 1.22.6.0
Current database path: /home/guyutongxue/.cache/vscode-cpptools/2555eb2c5ee6a91cb654bde2b78a9981/.browse.VC.db
Translation Unit Mappings:
[ /home/guyutongxue/temp/cpp/source_location.cpp - source TU]:
Translation Unit Configurations:
[ /home/guyutongxue/temp/cpp/source_location.cpp ]
Process ID: 1156233
Memory Usage: 57 MB
Compiler Path: /home/linuxbrew/.linuxbrew/bin/g++-14
Includes:
System Includes:
/home/linuxbrew/.linuxbrew/Cellar/gcc/14.2.0/include/c++/14
/home/linuxbrew/.linuxbrew/Cellar/gcc/14.2.0/include/c++/14/x86_64-pc-linux-gnu
/home/linuxbrew/.linuxbrew/Cellar/gcc/14.2.0/include/c++/14/backward
/home/linuxbrew/.linuxbrew/Cellar/gcc/14.2.0/lib/gcc/current/gcc/x86_64-pc-linux-gnu/14/include
/home/linuxbrew/.linuxbrew/Cellar/gcc/14.2.0/lib/gcc/current/gcc/x86_64-pc-linux-gnu/14/include-fixed/x86_64-linux-gnu
/home/linuxbrew/.linuxbrew/Cellar/gcc/14.2.0/lib/gcc/current/gcc/x86_64-pc-linux-gnu/14/include-fixed
/home/linuxbrew/.linuxbrew/Cellar/gcc/14.2.0/include
/home/linuxbrew/.linuxbrew/include
/usr/include/x86_64-linux-gnu
/usr/include
Standard Version: c++23
IntelliSense Mode: linux-gcc-x64
Other Flags:
--g++
--gnu_version=140200
Total Memory Usage: 57 MB
------- Workspace parsing diagnostics -------
Number of files discovered (not excluded): 25989
Other Extensions
N/A
Additional context
No response