Skip to content

constexpr std::array out-of-bounds array index access compiles without warnings or errors #76362

@dyumin

Description

@dyumin

The following code

#include <array>

constexpr std::array Array = {1, 2};

int main()
{
    return Array[3];
}

successfully compiles with --std=c++20 -O3 -Wall -Werror -Wpedantic -Winvalid-constexpr on clang 17.0.1.

godbolt link

jfyi
constexpr int Array[] = {1, 2}; produces compillation error error: array index 3 is past the end of the array (that has type 'const int[2]') [-Werror,-Warray-bounds] as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerfalse-negativeWarning doesn't fire when it shouldundefined behaviour

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions