microsoft / microsoft/vscode-cpptools

`std::source_location::function_name` gets inconsistent results with GCC/Clang

Open
#12,781 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug investigate: repro Language Service
Dominant language
TypeScript
Stars
6.2k
Forks
1.7k
Avg merge
14h 46m
Merged PRs (30d)
61

Description

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:

  1. Configured to a C++20-ready GCC/Clang compiler;
  2. 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__});
}

截图 2024-09-29 14-49-24

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

Language Server Log

Other Extensions

N/A

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the supplied source_location.cpp example, C++23 configuration, and GCC or Clang, then inspect the IntelliSense handling of std::source_location::function_name. Compare the extension result with PRETTY_FUNCTION and func; done means the static assertions match the compiler's function_name behavior for the reported case.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.