http://llvm.org/bugs/show_bug.cgi?id=19741
Bug ID: 19741
Summary: clang incorrectly rejects constexpr constructor which
modified member variable in its body
Product: clang
Version: 3.4
Hardware: PC
OS: Windows NT
Status: NEW
Severity: normal
Priority: P
Component: C++1y
Assignee: [email protected]
Reporter: [email protected]
CC: [email protected]
Classification: Unclassified
struct A {
int a = 0;
constexpr A() { a = 1; }
};
constexpr bool f() {
constexpr A a;
static_assert(a.a == 1, ""); // L1: OK
return a.a == 1;
}
static_assert(f(), ""); // L2: Error, can not modify A::a in constexpr
- Online Compiler URL: http://goo.gl/jni6Em
- Compiler: clang 3.4 (with -std=c++1y)
- System: Linux 3.2
The constructor satisfies all the conditions listed in ยง7.1.5/4 of N3936.
However, clang complains:
clang++ -stdlib=libc++ -std=c++1y a.cpp -c -o a.o -Wall
a.cpp:11:15: error: static_assert expression is not an integral constant
expression
static_assert(f(), ""); // L2: Error
^~~
a.cpp:3:23: note: modification of object of const-qualified type 'const int' is
not allowed in a constant expression
constexpr A() { a = 1; }
^
a.cpp:7:17: note: in call to 'A()'
constexpr A a;
^
a.cpp:11:15: note: in call to 'f()'
static_assert(f(), ""); // L2: Error
^
1 error generated.
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs