microsoft / microsoft/vscode-cpptools
`std::source_location::function_name` gets inconsistent results with GCC/Clang
Nessuno ha ancora preso questa issue.
- Lingua principale
- TypeScript
- Stelle
- 6.2k
- Fork
- 1.7k
- Merge medio
- 14h 46m
- PR unite (30g)
- 61
Descrizione
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_asserts 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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia riproducendo il problema con l’esempio fornito source_location.cpp, la configurazione C++23 e GCC o Clang, quindi esamina la gestione di std::source_location::function_name da parte di IntelliSense. Confronta il risultato dell’estensione con PRETTY_FUNCTION e func; il lavoro è completato quando le static assertions corrispondono al comportamento di function_name del compilatore per il caso segnalato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- cpp
- Ambito
- tooling
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100