Delete Tensor constructor that takes a pointer. Otherwise, say, std::make_unique<Tensor>(GetTensorSomewhereThatActuallyReturnsAPointer()) would construct boolean tensor without a compile time error.

PiperOrigin-RevId: 311778946
Change-Id: Ibdb69ff7c4a9697028ed30ac40ffb0797b4493f9
This commit is contained in:
Anna R 2020-05-15 12:20:44 -07:00 committed by TensorFlower Gardener
parent aa002d9a78
commit 28229ffdbf
1 changed files with 7 additions and 0 deletions

View File

@ -18,6 +18,7 @@ limitations under the License.
#include <cstdint>
#include <type_traits>
#include "third_party/eigen3/unsupported/Eigen/CXX11/Tensor"
#include "tensorflow/core/framework/allocator.h"
#include "tensorflow/core/framework/tensor_shape.h"
@ -239,6 +240,12 @@ class Tensor {
/// are not valid.
Tensor(Tensor&& other);
// Explicitly delete constructor that take a pointer (except char*)
// so that the pointer doesn't get implicitly cast to bool.
template <typename T, typename std::enable_if<!std::is_same<T, char>::value,
T>::type* = nullptr>
explicit Tensor(T* t) = delete;
~Tensor();
/// Returns the data type.