<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Rejects valid subscript expression on array of unknown bound in constant expression"
   href="https://bugs.llvm.org/show_bug.cgi?id=48402">48402</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Rejects valid subscript expression on array of unknown bound in constant expression
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++11
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>leni536@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>clang version 12.0.0 (<a href="https://github.com/llvm/llvm-project.git">https://github.com/llvm/llvm-project.git</a>
2518433f861fcb877d0a7bdd9aec1aec1f77505a)

command line options: -std=c++11 -pedantic-errors

Also reproducible with c++14, c++17 and c++20

```
extern const int arr[];
constexpr const int (&arrref)[] = arr;

constexpr int arr[2] = {1,2};

constexpr int x = arrref[0];
```

error: constexpr variable 'x' must be initialized by a constant expression
constexpr int x = arrref[0];
              ^   ~~~~~~~~~
note: read of element of array without known bound is not allowed in a constant
expression
constexpr int x = arrref[0];

Accessing elements through arrays of unknown bound is not explicitly forbidden
in constant expressions, so I think it is valid.

The followings are accepted:

```
extern const int arr[];
constexpr const int * ptr = arr;

constexpr int arr[2] = {1,2};

constexpr int x = ptr[0];
```

```
extern const int arr[];
constexpr const int (&arrref)[] = arr;

constexpr int arr[2] = {1,2};

constexpr const int* decay() {
    return arrref;
}

constexpr int x = decay()[0];
```

P0388 is accepted in C++20 and will enable other ways of creating subscript
constant expressions to arrays of unknown bound. Related gcc bug:
<a href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97645">https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97645</a></pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>