<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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 --- - Subexpression not valid in a constant expression even when it is valid"
   href="https://llvm.org/bugs/show_bug.cgi?id=27989">27989</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Subexpression not valid in a constant expression even when it is valid
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>3.8
          </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>normal
          </td>
        </tr>

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

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

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

        <tr>
          <th>Reporter</th>
          <td>michele.caini@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Consider the following code:

    template<int... V>
    static constexpr int f(int v) {
        int a[] = { (v ^= V, 0)... };       // Line 3
        return v;
    }

    static constexpr int i = f<0x00>(0x11); // Line 7

    int main() { }

It doesn't compile with the following error:

main.cpp:7:22: error: constexpr variable 'i' must be initialized by a constant
expression
[...]
main.cpp:3:23: note: subexpression not valid in a constant expression

Note that it doesn't work as well even if no templates are involved:

    static constexpr int mix(int v, int u) {
        int a[] = { (v ^= u, 0) };
        return v;
    }

    static constexpr int mf = mix(0x11, 0x00);

    int main() { }

For such kind of assignments are allowed in constant expressions, it should
compile.</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>