Cleanup: Clang-Tidy, modernize-make-unique

This commit is contained in:
Sergey Sharybin 2020-11-06 16:05:40 +01:00
parent ce70f2e1e0
commit 3cb4c51308
9 changed files with 34 additions and 31 deletions

View File

@ -45,7 +45,6 @@ Checks: >
-modernize-loop-convert, -modernize-loop-convert,
-modernize-pass-by-value, -modernize-pass-by-value,
-modernize-use-default-member-init, -modernize-use-default-member-init,
-modernize-make-unique,
-modernize-raw-string-literal, -modernize-raw-string-literal,
-modernize-avoid-bind, -modernize-avoid-bind,
-modernize-use-override, -modernize-use-override,

View File

@ -519,7 +519,7 @@ class IMeshArena::IMeshArenaImpl : NonCopyable, NonMovable {
IMeshArena::IMeshArena() IMeshArena::IMeshArena()
{ {
pimpl_ = std::unique_ptr<IMeshArenaImpl>(new IMeshArenaImpl()); pimpl_ = std::unique_ptr<IMeshArenaImpl>(std::make_unique<IMeshArenaImpl>());
} }
IMeshArena::~IMeshArena() IMeshArena::~IMeshArena()

View File

@ -419,9 +419,9 @@ TEST(map, Clear)
TEST(map, UniquePtrValue) TEST(map, UniquePtrValue)
{ {
auto value1 = std::unique_ptr<int>(new int()); auto value1 = std::unique_ptr<int>(std::make_unique<int>());
auto value2 = std::unique_ptr<int>(new int()); auto value2 = std::unique_ptr<int>(std::make_unique<int>());
auto value3 = std::unique_ptr<int>(new int()); auto value3 = std::unique_ptr<int>(std::make_unique<int>());
int *value1_ptr = value1.get(); int *value1_ptr = value1.get();
@ -429,12 +429,12 @@ TEST(map, UniquePtrValue)
map.add_new(1, std::move(value1)); map.add_new(1, std::move(value1));
map.add(2, std::move(value2)); map.add(2, std::move(value2));
map.add_overwrite(3, std::move(value3)); map.add_overwrite(3, std::move(value3));
map.lookup_or_add_cb(4, []() { return std::unique_ptr<int>(new int()); }); map.lookup_or_add_cb(4, []() { return std::unique_ptr<int>(std::make_unique<int>()); });
map.add_new(5, std::unique_ptr<int>(new int())); map.add_new(5, std::unique_ptr<int>(std::make_unique<int>()));
map.add(6, std::unique_ptr<int>(new int())); map.add(6, std::unique_ptr<int>(std::make_unique<int>()));
map.add_overwrite(7, std::unique_ptr<int>(new int())); map.add_overwrite(7, std::unique_ptr<int>(std::make_unique<int>()));
map.lookup_or_add(8, std::unique_ptr<int>(new int())); map.lookup_or_add(8, std::unique_ptr<int>(std::make_unique<int>()));
map.pop_default(9, std::unique_ptr<int>(new int())); map.pop_default(9, std::unique_ptr<int>(std::make_unique<int>()));
EXPECT_EQ(map.lookup(1).get(), value1_ptr); EXPECT_EQ(map.lookup(1).get(), value1_ptr);
EXPECT_EQ(map.lookup_ptr(100), nullptr); EXPECT_EQ(map.lookup_ptr(100), nullptr);

View File

@ -221,10 +221,10 @@ TEST(set, OftenAddRemoveContained)
TEST(set, UniquePtrValues) TEST(set, UniquePtrValues)
{ {
Set<std::unique_ptr<int>> set; Set<std::unique_ptr<int>> set;
set.add_new(std::unique_ptr<int>(new int())); set.add_new(std::unique_ptr<int>(std::make_unique<int>()));
auto value1 = std::unique_ptr<int>(new int()); auto value1 = std::unique_ptr<int>(std::make_unique<int>());
set.add_new(std::move(value1)); set.add_new(std::move(value1));
set.add(std::unique_ptr<int>(new int())); set.add(std::unique_ptr<int>(std::make_unique<int>()));
EXPECT_EQ(set.size(), 3); EXPECT_EQ(set.size(), 3);
} }

View File

@ -170,8 +170,8 @@ TEST(stack, Peek)
TEST(stack, UniquePtrValues) TEST(stack, UniquePtrValues)
{ {
Stack<std::unique_ptr<int>> stack; Stack<std::unique_ptr<int>> stack;
stack.push(std::unique_ptr<int>(new int())); stack.push(std::unique_ptr<int>(std::make_unique<int>()));
stack.push(std::unique_ptr<int>(new int())); stack.push(std::unique_ptr<int>(std::make_unique<int>()));
std::unique_ptr<int> a = stack.pop(); std::unique_ptr<int> a = stack.pop();
std::unique_ptr<int> &b = stack.peek(); std::unique_ptr<int> &b = stack.peek();
UNUSED_VARS(a, b); UNUSED_VARS(a, b);

View File

@ -142,9 +142,9 @@ TEST(vector_set, AddMultipleTimes)
TEST(vector_set, UniquePtrValue) TEST(vector_set, UniquePtrValue)
{ {
VectorSet<std::unique_ptr<int>> set; VectorSet<std::unique_ptr<int>> set;
set.add_new(std::unique_ptr<int>(new int())); set.add_new(std::unique_ptr<int>(std::make_unique<int>()));
set.add(std::unique_ptr<int>(new int())); set.add(std::unique_ptr<int>(std::make_unique<int>()));
set.index_of_try(std::unique_ptr<int>(new int())); set.index_of_try(std::unique_ptr<int>(std::make_unique<int>()));
std::unique_ptr<int> value = set.pop(); std::unique_ptr<int> value = set.pop();
UNUSED_VARS(value); UNUSED_VARS(value);
} }

View File

@ -456,10 +456,10 @@ TEST(vector, AppendNTimes)
TEST(vector, UniquePtrValue) TEST(vector, UniquePtrValue)
{ {
Vector<std::unique_ptr<int>> vec; Vector<std::unique_ptr<int>> vec;
vec.append(std::unique_ptr<int>(new int())); vec.append(std::unique_ptr<int>(std::make_unique<int>()));
vec.append(std::unique_ptr<int>(new int())); vec.append(std::unique_ptr<int>(std::make_unique<int>()));
vec.append(std::unique_ptr<int>(new int())); vec.append(std::unique_ptr<int>(std::make_unique<int>()));
vec.append(std::unique_ptr<int>(new int())); vec.append(std::unique_ptr<int>(std::make_unique<int>()));
EXPECT_EQ(vec.size(), 4); EXPECT_EQ(vec.size(), 4);
std::unique_ptr<int> &a = vec.last(); std::unique_ptr<int> &a = vec.last();

View File

@ -27,6 +27,8 @@ namespace Freestyle {
template<typename T> class AutoPtr : public std::unique_ptr<T> { template<typename T> class AutoPtr : public std::unique_ptr<T> {
public: public:
using std::unique_ptr<T>::unique_ptr;
AutoPtr() : std::unique_ptr<T>() AutoPtr() : std::unique_ptr<T>()
{ {
} }
@ -42,6 +44,8 @@ template<typename T> class AutoPtr : public std::unique_ptr<T> {
other.release(); other.release();
} }
using std::unique_ptr<T>::operator=;
template<typename X> AutoPtr &operator=(AutoPtr<X> &other) = delete; template<typename X> AutoPtr &operator=(AutoPtr<X> &other) = delete;
}; };

View File

@ -1381,17 +1381,17 @@ void ViewMapBuilder::ComputeCumulativeVisibility(ViewMap *ioViewMap,
AutoPtr<OccluderSource> source; AutoPtr<OccluderSource> source;
if (_orthographicProjection) { if (_orthographicProjection) {
transform.reset(new BoxGrid::Transform); transform = std::make_unique<BoxGrid::Transform>();
} }
else { else {
transform.reset(new SphericalGrid::Transform); transform = std::make_unique<SphericalGrid::Transform>();
} }
if (cull) { if (cull) {
source.reset(new CulledOccluderSource(*transform, we, *ioViewMap, true)); source = std::make_unique<CulledOccluderSource>(*transform, we, *ioViewMap, true);
} }
else { else {
source.reset(new OccluderSource(*transform, we)); source = std::make_unique<OccluderSource>(*transform, we);
} }
AutoPtr<GridDensityProvider> density(factory.newGridDensityProvider(*source, bbox, *transform)); AutoPtr<GridDensityProvider> density(factory.newGridDensityProvider(*source, bbox, *transform));
@ -1419,17 +1419,17 @@ void ViewMapBuilder::ComputeDetailedVisibility(ViewMap *ioViewMap,
AutoPtr<OccluderSource> source; AutoPtr<OccluderSource> source;
if (_orthographicProjection) { if (_orthographicProjection) {
transform.reset(new BoxGrid::Transform); transform = std::make_unique<BoxGrid::Transform>();
} }
else { else {
transform.reset(new SphericalGrid::Transform); transform = std::make_unique<SphericalGrid::Transform>();
} }
if (cull) { if (cull) {
source.reset(new CulledOccluderSource(*transform, we, *ioViewMap, true)); source = std::make_unique<CulledOccluderSource>(*transform, we, *ioViewMap, true);
} }
else { else {
source.reset(new OccluderSource(*transform, we)); source = std::make_unique<OccluderSource>(*transform, we);
} }
AutoPtr<GridDensityProvider> density(factory.newGridDensityProvider(*source, bbox, *transform)); AutoPtr<GridDensityProvider> density(factory.newGridDensityProvider(*source, bbox, *transform));