Skip to content

Attempt to access run-time storage error #8673

@pparuzel

Description

@pparuzel

Bug type: Language Service

Describe the bug

  • OS and Version: MacOS Monterey 12.1 (M1 processor)
  • VS Code Version:
    • Version: 1.63.2
    • Commit: 899d46d82c4c95423fb7e10e68eba52050e30ba3
    • Date: 2021-12-15T09:38:17.605Z (1 mo ago)
    • Electron: 13.5.2
    • Chromium: 91.0.4472.164
    • Node.js: 14.16.0
    • V8: 9.1.269.39-electron.0
    • OS: Darwin arm64 21.2.0
  • C/C++ Extension Version: v1.8.0-insiders2
  • Other extensions you installed (and if the issue persists after disabling them):
    • CMake v0.0.17

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Language ServiceVisual StudioInherited from Visual StudiobugfixedCheck the Milestone for the release in which the fix is or will be available.

    Type

    Projects

    Status

    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions