<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 --- - void() incorrectly rejected as non-constant expression"
   href="https://llvm.org/bugs/show_bug.cgi?id=30592">30592</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>void() incorrectly rejected as non-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>Windows NT
          </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++
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>Casey@Carter.net
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>r283037 miscompiles this program:

int main() {
    constexpr int foo = (void(), 0);
    return foo;
}

with diagnosis:

prog.cc:2:26: error: constexpr variable 'foo' must be initialized by a constant
expression
    constexpr int foo = (void(), 0);
                        ~^~~~~~~~~~

Conversions to void, e.g. void(42) or static_cast<void>(42), are acceptable,
but the prvalue void() is not. It should be, since:

* void is a simple-type-specifier,

* simple-type-specifier ( expression-list_opt ) is a postfix-expression, the
behavior of which is specified in [expr.type.conv]/1 "If the type is (possibly
cv-qualified) void and the initializer is (), the expression is a prvalue of
the specified type that performs no initialization."

* postfix-expression (through a long chain of intermediaries) is a
conditional-expression,

* a conditional-expression is a core constant expression unless it violates one
of the rules listed in [expr.const]/2, which void() does not, nor does it
"evaluate an operation that has undefined behavior,"

* [expr.const]/5 defines "A constant expression is either a glvalue core
constant expression [...stuff that doesn't apply to prvalues...], or a prvalue
core constant expression whose value satisfies the following constraints:

  * if the value is an object of class type [...stuff that does not apply to
void()...]

  * if the value is of pointer type [...ibid...]

  * if the value is an object of class or array type [...ibid...]

To the best of my ability to determine, void() is a constant expression.</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>