microsoft / microsoft/vscode-cpptools

consteval not correctly evaluated

Aperta
#14,401 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug Language Service Visual Studio
Lingua principale
TypeScript
Stelle
6.2k
Fork
1.7k
Merge medio
14h 46m
PR unite (30g)
61

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia riproducendo il comportamento dell'hover con l'esempio C++ consteval nell'issue, confrontando l'accesso diretto al membro con l'inizializzazione di register_address. Traccia il percorso di valutazione dell'hover di IntelliSense per i risultati delle funzioni consteval e verifica come vengono visualizzati i valori. L'attività è completata quando l'hover su demo::get_register("register_name").address mostra costantemente 0x1000, con una copertura per il caso segnalato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
cpp
Ambito
developer-experience, tooling
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.