Skip to content

Valid code fails with "reference to local variable declared in enclosing function" #140632

Closed
@Ignition

Description

@Ignition
#include <array>
#include <ranges>

int main() {
    constexpr auto v = std::array{1, 2, 3, 4, 5, 6};
    for (auto const& [t0, t1, t2] : v | std::views::adjacent<3>) {
    }
}

error: reference to local variable 'v' declared in enclosing function 'main'

Works in GCC 15.1
Error in clang 20.1.0
Works if you remove constexpr

godbolt link

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"constexprAnything related to constant evaluation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions