[libcxx] r300158 - Add tests that std::unique_ptr's default constructor is constexpr.
Eric Fiselier via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 12 18:11:59 PDT 2017
Author: ericwf
Date: Wed Apr 12 20:11:58 2017
New Revision: 300158
URL: http://llvm.org/viewvc/llvm-project?rev=300158&view=rev
Log:
Add tests that std::unique_ptr's default constructor is constexpr.
std::unique_ptr's default constructor must be constexpr in order
to allow constant initialization to take place for static objects;
Even though we can never have a constexpr unique_ptr variable since
it's not a literal type.
This patch adds tests that constant initialization takes place by
using the __attribute__((require_constant_initialization)) macro.
Added:
libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default.pass.cpp
- copied, changed from r300156, libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default01.pass.cpp
libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default_allows_incomplete.pass.cpp
- copied, changed from r300156, libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default02.pass.cpp
Removed:
libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default01.pass.cpp
libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default02.pass.cpp
Modified:
libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default.pass.cpp
Copied: libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default.pass.cpp (from r300156, libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default01.pass.cpp)
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default.pass.cpp?p2=libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default.pass.cpp&p1=libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default01.pass.cpp&r1=300156&r2=300158&rev=300158&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default01.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default.pass.cpp Wed Apr 12 20:11:58 2017
@@ -17,31 +17,34 @@
#include <memory>
#include <cassert>
+#include "test_macros.h"
-class Deleter
-{
- int state_;
+#if defined(_LIBCPP_VERSION)
+_LIBCPP_SAFE_STATIC std::unique_ptr<int[]> global_static_unique_ptr;
+#endif
- Deleter(Deleter&);
- Deleter& operator=(Deleter&);
+class Deleter {
+ int state_;
+
+ Deleter(Deleter&);
+ Deleter& operator=(Deleter&);
public:
- Deleter() : state_(5) {}
+ Deleter() : state_(5) {}
- int state() const {return state_;}
+ int state() const { return state_; }
- void operator()(void*) {}
+ void operator()(void*) {}
};
-int main()
-{
- {
+int main() {
+ {
std::unique_ptr<int[]> p;
assert(p.get() == 0);
- }
- {
+ }
+ {
std::unique_ptr<int[], Deleter> p;
assert(p.get() == 0);
assert(p.get_deleter().state() == 5);
- }
+ }
}
Removed: libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default01.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default01.pass.cpp?rev=300157&view=auto
==============================================================================
--- libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default01.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default01.pass.cpp (removed)
@@ -1,47 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test unique_ptr default ctor
-
-// default unique_ptr ctor should only require default Deleter ctor
-
-#include <memory>
-#include <cassert>
-
-class Deleter
-{
- int state_;
-
- Deleter(Deleter&);
- Deleter& operator=(Deleter&);
-
-public:
- Deleter() : state_(5) {}
-
- int state() const {return state_;}
-
- void operator()(void*) {}
-};
-
-int main()
-{
- {
- std::unique_ptr<int[]> p;
- assert(p.get() == 0);
- }
- {
- std::unique_ptr<int[], Deleter> p;
- assert(p.get() == 0);
- assert(p.get_deleter().state() == 5);
- }
-}
Removed: libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default02.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default02.pass.cpp?rev=300157&view=auto
==============================================================================
--- libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default02.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default02.pass.cpp (removed)
@@ -1,87 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <memory>
-
-// unique_ptr
-
-// Test default unique_ptr<T[]> ctor
-
-// default unique_ptr<T[]> ctor shouldn't require complete type
-
-#include <memory>
-#include <cassert>
-
-struct A;
-
-class Deleter
-{
- int state_;
-
- Deleter(Deleter&);
- Deleter& operator=(Deleter&);
-
-public:
- Deleter() : state_(5) {}
-
- int state() const {return state_;}
-
- void operator()(A* p);
-};
-
-void check(int i);
-
-template <class D = std::default_delete<A> >
-struct B
-{
- std::unique_ptr<A[], D> a_;
- B();
- ~B();
-
- A* get() const {return a_.get();}
- D& get_deleter() {return a_.get_deleter();}
-};
-
-int main()
-{
- {
- B<> s;
- assert(s.get() == 0);
- }
- check(0);
- {
- B<Deleter> s;
- assert(s.get() == 0);
- assert(s.get_deleter().state() == 5);
- }
- check(0);
-}
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- ~A() {--count;}
-};
-
-int A::count = 0;
-
-void Deleter::operator()(A* p) {delete p;}
-
-void check(int i)
-{
- assert(A::count == i);
-}
-
-template <class D>
-B<D>::B() {}
-
-template <class D>
-B<D>::~B() {}
Copied: libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default_allows_incomplete.pass.cpp (from r300156, libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default02.pass.cpp)
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default_allows_incomplete.pass.cpp?p2=libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default_allows_incomplete.pass.cpp&p1=libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default02.pass.cpp&r1=300156&r2=300158&rev=300158&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default02.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default_allows_incomplete.pass.cpp Wed Apr 12 20:11:58 2017
@@ -20,65 +20,58 @@
struct A;
-class Deleter
-{
- int state_;
+class Deleter {
+ int state_;
- Deleter(Deleter&);
- Deleter& operator=(Deleter&);
+ Deleter(Deleter&);
+ Deleter& operator=(Deleter&);
public:
- Deleter() : state_(5) {}
+ Deleter() : state_(5) {}
- int state() const {return state_;}
+ int state() const { return state_; }
- void operator()(A* p);
+ void operator()(A* p);
};
void check(int i);
-template <class D = std::default_delete<A> >
-struct B
-{
- std::unique_ptr<A[], D> a_;
- B();
- ~B();
+template <class D = std::default_delete<A>>
+struct B {
+ std::unique_ptr<A[], D> a_;
+ B();
+ ~B();
- A* get() const {return a_.get();}
- D& get_deleter() {return a_.get_deleter();}
+ A* get() const { return a_.get(); }
+ D& get_deleter() { return a_.get_deleter(); }
};
-int main()
-{
- {
+int main() {
+ {
B<> s;
assert(s.get() == 0);
- }
- check(0);
- {
+ }
+ check(0);
+ {
B<Deleter> s;
assert(s.get() == 0);
assert(s.get_deleter().state() == 5);
- }
- check(0);
+ }
+ check(0);
}
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- ~A() {--count;}
+struct A {
+ static int count;
+ A() { ++count; }
+ A(const A&) { ++count; }
+ ~A() { --count; }
};
int A::count = 0;
-void Deleter::operator()(A* p) {delete p;}
+void Deleter::operator()(A* p) { delete p; }
-void check(int i)
-{
- assert(A::count == i);
-}
+void check(int i) { assert(A::count == i); }
template <class D>
B<D>::B() {}
Modified: libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default.pass.cpp?rev=300158&r1=300157&r2=300158&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default.pass.cpp Wed Apr 12 20:11:58 2017
@@ -25,9 +25,14 @@
#include <memory>
#include <cassert>
+#include "test_macros.h"
#include "deleter_types.h"
+#if defined(_LIBCPP_VERSION)
+_LIBCPP_SAFE_STATIC std::unique_ptr<int> global_static_unique_ptr;
+#endif
+
struct IncompleteT;
void checkNumIncompleteTypeAlive(int i);
More information about the cfe-commits
mailing list