https://gcc.gnu.org/g:3a578f6fcb8b9e1b84584dc8a789dafa80c9e2ae
commit r17-2303-g3a578f6fcb8b9e1b84584dc8a789dafa80c9e2ae Author: Arsen Arsenović <[email protected]> Date: Fri Jun 19 18:21:14 2026 +0000 gcc/cp-tree: require that temp_override deduces on first constructor arg This helps force a conversion from the second argument into whatever type the variable truly is. This change ended up being unnecessary, but it is probably useful for others anyway. gcc/cp/ChangeLog: * cp-tree.h (temp_override): In provided-value constructor, don't deduce based on provided value. Diff: --- gcc/cp/cp-tree.h | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index a3be24b4fb54..8dac8c98b7a3 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -2256,6 +2256,17 @@ public: } }; +/* Wrapping a template parameter in type_identity_t hides it from template + argument deduction. */ +#if __cpp_lib_type_identity +using std::type_identity_t; +#else +template <typename T> +struct type_identity { typedef T type; }; +template <typename T> +using type_identity_t = typename type_identity<T>::type; +#endif + /* RAII sentinel that saves the value of a variable, optionally overrides it right away, and restores its value when the sentinel id destructed. */ @@ -2266,8 +2277,8 @@ class temp_override T& overridden_variable; T saved_value; public: - temp_override(T& var) : overridden_variable (var), saved_value (var) {} - temp_override(T& var, T overrider) + temp_override (T& var) : overridden_variable (var), saved_value (var) {} + temp_override (T& var, type_identity_t<T> overrider) : overridden_variable (var), saved_value (var) { overridden_variable = overrider; @@ -2275,17 +2286,6 @@ public: ~temp_override() { overridden_variable = saved_value; } }; -/* Wrapping a template parameter in type_identity_t hides it from template - argument deduction. */ -#if __cpp_lib_type_identity -using std::type_identity_t; -#else -template <typename T> -struct type_identity { typedef T type; }; -template <typename T> -using type_identity_t = typename type_identity<T>::type; -#endif - /* Object generator function for temp_override, so you don't need to write the type of the object as a template argument.
