[libcamera-devel] [PATCH] libcamera: controls: Disable ControlValue<T> construction from unsupported T

Laurent Pinchart laurent.pinchart at ideasonboard.com
Sat Oct 24 00:00:20 CEST 2020


The ControlValue<T> constructor for non-array values is a template
function that participates in overload resolution for all T types that
are not Span or std::string. Other T types that are not supported then
result in a compilation error.

This causes issues when calling an overloaded function that can accept
both a ControlValue and a Span with an std::array<U> parameter. The
first overload will be resolved using implicit construction of a
ControlValue from the std::array<U>, while the second overload will be
resolved using implicit construction of a Span<U> from the
std::array<U>. This results in a compilation error due to an ambiguous
function call.

The first overload is invalid, selecting it would result in a
compilation error in the ControlValue constructor, as the
ControlValue<T> constructor doesn't support std::array<U> for type T.
The compiler can't know about that, as overload resolution happens
earlier.

To fix it, we can disable the ControlValue<T> constructor for
unsupported types T, moving the type check from compilation of the
function to overload resolution. The constructor will not participate in
overload resolution, and the call won't be ambiguous. The end result is
the same for unsupported types, compilation will fail.

Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
---
 include/libcamera/controls.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h
index 3d7f4b0dc1a7..3b7f3347761e 100644
--- a/include/libcamera/controls.h
+++ b/include/libcamera/controls.h
@@ -97,6 +97,7 @@ public:
 
 #ifndef __DOXYGEN__
 	template<typename T, typename std::enable_if_t<!details::is_span<T>::value &&
+						       details::control_type<T>::value &&
 						       !std::is_same<std::string, std::remove_cv_t<T>>::value,
 						       std::nullptr_t> = nullptr>
 	ControlValue(const T &value)
-- 
Regards,

Laurent Pinchart



More information about the libcamera-devel mailing list