[libcamera-devel,2/2] libcamera: base: utils: Drop defopt
diff mbox series

Message ID 20221009044440.21499-3-laurent.pinchart@ideasonboard.com
State Accepted
Commit e0e54965df015b954d75ebe945221372f2dffb80
Headers show
Series
  • libcamera: Fix compilation with gcc 8.3.0
Related show

Commit Message

Laurent Pinchart Oct. 9, 2022, 4:44 a.m. UTC
utils::defopt causes compilation issues on gcc 8.0.0 to gcc 8.3.0,
likely due to bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86521
that was fixed in gcc 8.4.0. gcc 8.3.0 may be considered old (libcamera
requires gcc-8 or newer), but it is shipped by Debian 10 that has LTS
support until mid-2024.

As no workaround has been found to fix compilation on gcc 8.3.0 while
still retaining the functionality of utils::defopt, remove it from the
libcamera base library. This change could be reverted once support for
gcc-8 will be dropped.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 include/libcamera/base/utils.h | 14 ---------
 src/libcamera/base/utils.cpp   | 21 --------------
 test/utils.cpp                 | 53 ----------------------------------
 3 files changed, 88 deletions(-)

Patch
diff mbox series

diff --git a/include/libcamera/base/utils.h b/include/libcamera/base/utils.h
index ed88b7163770..eb7bcdf4c173 100644
--- a/include/libcamera/base/utils.h
+++ b/include/libcamera/base/utils.h
@@ -367,20 +367,6 @@  decltype(auto) abs_diff(const T &a, const T &b)
 		return a - b;
 }
 
-namespace details {
-
-struct defopt_t {
-	template<typename T>
-	operator T() const
-	{
-		return T{};
-	}
-};
-
-} /* namespace details */
-
-constexpr details::defopt_t defopt;
-
 } /* namespace utils */
 
 #ifndef __DOXYGEN__
diff --git a/src/libcamera/base/utils.cpp b/src/libcamera/base/utils.cpp
index 9cd6cb197243..6a307940448e 100644
--- a/src/libcamera/base/utils.cpp
+++ b/src/libcamera/base/utils.cpp
@@ -463,27 +463,6 @@  std::string toAscii(const std::string &str)
  * \a b
  */
 
-/**
- * \var defopt
- * \brief Constant used with std::optional::value_or() to create a
- * default-constructed object
- *
- * The std::optional<T>::value_or(U &&default_value) function returns the
- * contained value if available, or \a default_value if the std::optional has no
- * value. If the desired default value is a default-constructed T, the obvious
- * option is to call std::optional<T>::value_or(T{}). This approach has two
- * drawbacks:
- *
- * * The \a default_value T{} is constructed even if the std::optional instance
- *   has a value, which impacts efficiency.
- * * The T{} default constructor needs to be spelled out explicitly in the
- *   value_or() call, leading to long lines if the type is complex.
- *
- * The defopt variable solves these issues by providing a value that can be
- * passed to std::optional<T>::value_or() and get implicitly converted to a
- * default-constructed T.
- */
-
 } /* namespace utils */
 
 #ifndef __DOXYGEN__
diff --git a/test/utils.cpp b/test/utils.cpp
index 58b5a59dd17d..fc56e14ee734 100644
--- a/test/utils.cpp
+++ b/test/utils.cpp
@@ -170,55 +170,6 @@  protected:
 		return TestPass;
 	}
 
-	int testDefopt()
-	{
-		static bool defaultConstructed = false;
-
-		struct ValueType {
-			ValueType()
-				: value_(-1)
-			{
-				defaultConstructed = true;
-			}
-
-			ValueType(int value)
-				: value_(value)
-			{
-			}
-
-			int value_;
-		};
-
-		/*
-		 * Test that utils::defopt doesn't cause default-construction
-		 * of a ValueType instance when value_or(utils::defopt) is
-		 * called on a std::optional that has a value.
-		 */
-		std::optional<ValueType> opt = ValueType(0);
-		ValueType value = opt.value_or(utils::defopt);
-
-		if (defaultConstructed || value.value_ != 0) {
-			std::cerr << "utils::defopt didn't prevent default construction"
-				  << std::endl;
-			return TestFail;
-		}
-
-		/*
-		 * Then test that the ValueType is correctly default-constructed
-		 * when the std::optional has no value.
-		 */
-		opt = std::nullopt;
-		value = opt.value_or(utils::defopt);
-
-		if (!defaultConstructed || value.value_ != -1) {
-			std::cerr << "utils::defopt didn't cause default construction"
-				  << std::endl;
-			return TestFail;
-		}
-
-		return TestPass;
-	}
-
 	int run()
 	{
 		/* utils::hex() test. */
@@ -339,10 +290,6 @@  protected:
 		if (testDuration() != TestPass)
 			return TestFail;
 
-		/* utils::defopt test. */
-		if (testDefopt() != TestPass)
-			return TestFail;
-
 		return TestPass;
 	}
 };