Differential D113837 Diff 387054 clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-owning-memory.cpp
Changeset View
Changeset View
Standalone View
Standalone View
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-owning-memory.cpp
Show First 20 Lines • Show All 297 Lines • ▼ Show 20 Lines | struct HeapArray { // Ok, since destructor with owner | ||||
HeapArray() : _data(nullptr), size(0) {} // Ok | HeapArray() : _data(nullptr), size(0) {} // Ok | ||||
HeapArray(int size) : _data(new int[size]), size(size) {} // Ok | HeapArray(int size) : _data(new int[size]), size(size) {} // Ok | ||||
HeapArray(int size, T val) { | HeapArray(int size, T val) { | ||||
_data = new int[size]; // Ok | _data = new int[size]; // Ok | ||||
size = size; | size = size; | ||||
for (auto i = 0u; i < size; ++i) | for (auto i = 0u; i < size; ++i) | ||||
_data[i] = val; // Ok | _data[i] = val; // Ok | ||||
} | } | ||||
HeapArray(int size, T val, int *problematic) : _data{problematic}, size(size) {} // Bad | HeapArray(int size, T val, int *problematic) : _data{problematic}, size(size) {} // Bad | ||||
aaronpuchert: If the warning is looking at this in the original template, we're initializing a `gsl::owner<T… | |||||
// CHECK-NOTES: [[@LINE-1]]:50: warning: expected initialization of owner member variable with value of type 'gsl::owner<>'; got 'void' | // CHECK-NOTES: [[@LINE-1]]:50: warning: expected initialization of owner member variable with value of type 'gsl::owner<>'; got '<dependent type>' | ||||
// FIXME: void is incorrect type, probably wrong thing matched | // FIXME: <dependent type> is incorrect type, probably wrong thing matched | ||||
HeapArray(HeapArray &&other) : _data(other._data), size(other.size) { // Ok | HeapArray(HeapArray &&other) : _data(other._data), size(other.size) { // Ok | ||||
other._data = nullptr; // Ok | other._data = nullptr; // Ok | ||||
other.size = 0; | other.size = 0; | ||||
} | } | ||||
HeapArray<T> &operator=(HeapArray<T> &&other) { | HeapArray<T> &operator=(HeapArray<T> &&other) { | ||||
_data = other._data; // Ok, NOLINT warning here about bad types, why? | _data = other._data; // Ok, NOLINT warning here about bad types, why? | ||||
▲ Show 20 Lines • Show All 68 Lines • Show Last 20 Lines |
If the warning is looking at this in the original template, we're initializing a gsl::owner<T *> which is type-dependent. So we can't carry out the initialization yet.
Got the impression earlier that the lifetime checks want to “understand” templates which can of course not work because templates can be specialized, overload resolution is only performed on the instantiation, and so on.