microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.52k stars 1.55k forks source link

Attempt to access run-time storage error #8673

Open pparuzel opened 2 years ago

pparuzel commented 2 years ago

Bug type: Language Service

Describe the bug

Even though the program compiles fine on Apple Clang, Clang13, and GCC11 - IntelliSense reports an error in Problems Tab. image or if you change values[j] to values[i]: image

Minimal example

Here's the most minimal example I could create to reproduce:

#include <array>

template <std::size_t N>
constexpr auto transform(const std::array<float, N>& arr)
{
    std::array<int, N> values;
    for (std::size_t i{0}; const auto& k : arr)
    {
        constexpr auto j = 0;
        values[j] = k;  // change this j to i and you get a different error as well
        ++i;
    }
    return values;
}

int main()
{
    constexpr auto values = transform(std::array{0.f});
}

Expected behavior

There should be no errors in Problems Tab as this C++20 code is perfectly valid.

sean-mcmanus commented 2 years ago

Thanks for reporting this. I've filed a bug on our shared VS parser at https://developercommunity.visualstudio.com/t/C-IntelliSense-gives-incorrect-error-/1637986 .

(Note to team: I didn't file an internal bug, because this issue seems more widely applicable to many VS users).