From 28229ffdbf8d996449bf2ad8289d18201f21ca7b Mon Sep 17 00:00:00 2001 From: Anna R Date: Fri, 15 May 2020 12:20:44 -0700 Subject: [PATCH] Delete Tensor constructor that takes a pointer. Otherwise, say, std::make_unique(GetTensorSomewhereThatActuallyReturnsAPointer()) would construct boolean tensor without a compile time error. PiperOrigin-RevId: 311778946 Change-Id: Ibdb69ff7c4a9697028ed30ac40ffb0797b4493f9 --- tensorflow/core/framework/tensor.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tensorflow/core/framework/tensor.h b/tensorflow/core/framework/tensor.h index 54541be0b4f..744a14e007e 100644 --- a/tensorflow/core/framework/tensor.h +++ b/tensorflow/core/framework/tensor.h @@ -18,6 +18,7 @@ limitations under the License. #include #include + #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 ::value, + T>::type* = nullptr> + explicit Tensor(T* t) = delete; + ~Tensor(); /// Returns the data type.