microsoft / microsoft/vscode-cpptools
consteval not correctly evaluated
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 6.2k
- Forks
- 1.7k
- Avg merge
- 14h 46m
- Merged PRs (30d)
- 61
Description
Environment
- OS and Version: Linux, Ubuntu 24.04
- VS Code Version: 1.116.0
- C/C++ Extension Version: 1.31.5
- If using SSH remote, specify OS of remote machine: no
Bug Summary and Steps to Reproduce
Bug Summary:
The InteliSense output doesn't pars consteval correctly. Mose hover-over doesn't work for values of a struct returned by consteval.
Steps to reproduce:
#include <array>
#include <cstddef>
#include <cstdint>
#include <string_view>
namespace demo {
struct Register_t {
std::string_view name;
std::int64_t address;
};
inline constexpr auto registers = std::array{
Register_t{"register_name", 0x1000},
};
template <std::size_t N>
consteval const Register_t& find_register(std::string_view name, const std::array<Register_t, N>& regs) {
for (const auto& reg : regs) {
if (reg.name == name) {
return reg;
}
}
throw "Register not found";
}
consteval const Register_t& get_register(std::string_view name) { return find_register(name, registers); }
} // namespace demo
static constexpr std::int64_t register_address = demo::get_register("register_name").address;
static_assert(demo::get_register("register_name").address == 0x1000);
static_assert(register_address == 0x1000);
The mouse hover-over of demo::get_register("register_name").address just return int64_t demo::Register_t::address instead of the expected value 0x1000 as it is done through the assigned value in register_address
Expected behavior:
Mouse hover-over on demo::get_register("register_name").address shows also the value.
It seems that the behavior isn't that stable, means that some times the value is returned and sometimes not. e.g. in Version 1.29.3 the values are shown when it is used for template initialization.
Configuration and Logs
-
Other Extensions
ms-vscode.cmake-tools
ms-vscode.cpptools-themes
ms-vscode.cpptools-extension-pack
ms-vscode.cpp-devtools
Additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the hover behavior with the consteval C++ example in the issue, comparing direct member access with the register_address initialization. Trace the IntelliSense hover evaluation path for consteval function results and inspect how values are displayed. Done means the hover over demo::get_register("register_name").address consistently shows 0x1000, with coverage for the reported case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- developer-experience, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100