From 77079c8125d1dd9fce21be15909afaa3a380f07d Mon Sep 17 00:00:00 2001 From: rleigh-electradx Date: Tue, 4 Aug 2026 19:04:19 +0100 Subject: [PATCH] Fix etl::common_type decaying both arguments to T2 (#1529) The two-type etl::common_type specialization recursed with decay twice when either argument was not already decayed, so etl::common_type_t yielded int instead of long. Recurse with decay and decay, matching the cppreference sample implementation, and add regression tests comparing against std::common_type for reference-type arguments. Co-authored-by: John Wellbelove --- include/etl/type_traits.h | 2 +- test/test_type_traits.cpp | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/include/etl/type_traits.h b/include/etl/type_traits.h index 13d21810..6ecf9451 100644 --- a/include/etl/type_traits.h +++ b/include/etl/type_traits.h @@ -3724,7 +3724,7 @@ namespace etl struct common_type : etl::conditional< etl::is_same::type>::value && etl::is_same::type>::value, private_common_type::common_type_2_impl, - common_type::type, typename etl::decay::type>>::type + common_type::type, typename etl::decay::type>>::type { }; diff --git a/test/test_type_traits.cpp b/test/test_type_traits.cpp index 6756d6d9..603c992b 100644 --- a/test/test_type_traits.cpp +++ b/test/test_type_traits.cpp @@ -2268,5 +2268,23 @@ namespace CHECK_TRUE(etl::is_unsigned::value); #endif } + +#if ETL_USING_CPP11 + //************************************************************************* + TEST(test_common_type) + { + // Reference types must decay to the same result as std::common_type. + CHECK((etl::is_same, long>::value)); + CHECK((etl::is_same, std::common_type::type>::value)); + CHECK((etl::is_same, long>::value)); + CHECK((etl::is_same, std::common_type::type>::value)); + CHECK((etl::is_same, char>::value)); + CHECK((etl::is_same, std::common_type::type>::value)); + + // Already decayed types. + CHECK((etl::is_same, long>::value)); + CHECK((etl::is_same, std::common_type::type>::value)); + } +#endif } } // namespace