diff options
author | David L. Jones <dlj@google.com> | 2017-01-09 21:38:07 +0000 |
---|---|---|
committer | David L. Jones <dlj@google.com> | 2017-01-09 21:38:07 +0000 |
commit | f55ce36c029dd68577743179884ed43d76697937 (patch) | |
tree | 8da157b6088c19aea80cc9162a38a781520a1c6f /clang/test/CXX/basic/basic.start/basic.start.init | |
parent | a84ab073d968415eab0c44d6e695bd2072f4c027 (diff) | |
download | bcm5719-llvm-f55ce36c029dd68577743179884ed43d76697937.tar.gz bcm5719-llvm-f55ce36c029dd68577743179884ed43d76697937.zip |
Allow constexpr construction of subobjects unconditionally, not just in C++14.
Summary:
Per https://wg21.link/CWG1677, the C++11 standard did not clarify that constant
initialization of an object allowed constexpr brace-or-equal initialization of
subobjects:
struct foo_t { union { int i; volatile int j; } u; };
__attribute__((__require_constant_initialization__))
static const foo_t x = {{0}};
Because foo_t::u has a volatile member, the initializer for x fails. However,
there is really no good reason, because this:
union foo_u { int i; volatile int j; };
__attribute__((__require_constant_initialization__))
static const foo_u x = {0};
does have a constant initializer.
(This was triggered by musl's pthread_mutex_t type when building under C++11.)
Reviewers: rsmith
Subscribers: EricWF, cfe-commits
Differential Revision: https://reviews.llvm.org/D28427
llvm-svn: 291480
Diffstat (limited to 'clang/test/CXX/basic/basic.start/basic.start.init')
-rw-r--r-- | clang/test/CXX/basic/basic.start/basic.start.init/p2.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/clang/test/CXX/basic/basic.start/basic.start.init/p2.cpp b/clang/test/CXX/basic/basic.start/basic.start.init/p2.cpp new file mode 100644 index 00000000000..36158210ac9 --- /dev/null +++ b/clang/test/CXX/basic/basic.start/basic.start.init/p2.cpp @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -verify %s -pedantic-errors -std=c++11 +// RUN: %clang_cc1 -verify %s -pedantic-errors -std=c++14 +// expected-no-diagnostics + +struct foo_t { + union { + int i; + volatile int j; + } u; +}; + +__attribute__((__require_constant_initialization__)) +static const foo_t x = {{0}}; + +union foo_u { + int i; + volatile int j; +}; + +__attribute__((__require_constant_initialization__)) +static const foo_u y = {0}; |