https://llvm.org/bugs/show_bug.cgi?id=30592
Bug ID: 30592 Summary: void() incorrectly rejected as non-constant expression Product: clang Version: trunk Hardware: PC OS: Windows NT Status: NEW Severity: normal Priority: P Component: C++ Assignee: unassignedclangb...@nondot.org Reporter: ca...@carter.net CC: dgre...@apple.com, llvm-bugs@lists.llvm.org Classification: Unclassified 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. -- You are receiving this mail because: You are on the CC list for the bug.
_______________________________________________ llvm-bugs mailing list llvm-bugs@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs