From 581bb274956fcf7e781384342e88cd8fa35b1336 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sat, 24 Oct 2020 00:45:32 +0300 Subject: libcamera: controls: Disable ControlValue construction from unsupported T The ControlValue 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 parameter. The first overload will be resolved using implicit construction of a ControlValue from the std::array, while the second overload will be resolved using implicit construction of a Span from the std::array. 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 constructor doesn't support std::array for type T. The compiler can't know about that, as overload resolution happens earlier. To fix it, we can disable the ControlValue 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. Acked-by: Kieran Bingham Reviewed-by: Jacopo Mondi Signed-off-by: Laurent Pinchart --- include/libcamera/controls.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include/libcamera/controls.h') diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index 80944efc..a556328c 100644 --- a/include/libcamera/controls.h +++ b/include/libcamera/controls.h @@ -96,6 +96,7 @@ public: #ifndef __DOXYGEN__ template::value && + details::control_type::value && !std::is_same>::value, std::nullptr_t> = nullptr> ControlValue(const T &value) -- cgit v1.2.1