~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.
+
+ Use as auto x = make_temp_override (flag); */
+
+template <typename T>
+inline temp_override<T>
+make_temp_override (T& var)
+{
+ return { var };
+}
+
+/* Likewise, but use as auto x = make_temp_override (flag, value); */
+
+template <typename T>
+inline temp_override<T>
+make_temp_override (T& var, type_identity_t<T> overrider)
+{
+ return { var, overrider };
+}
+
/* The cached class binding level, from the most recently exited
class, or NULL if none. */
/* An object declared as __attribute__((deprecated)) suppresses
warnings of uses of other deprecated items. */
- temp_override<deprecated_states> ds (deprecated_state);
+ auto ds = make_temp_override (deprecated_state);
if (attrlist && lookup_attribute ("deprecated", *attrlist))
deprecated_state = DEPRECATED_SUPPRESS;
&& (!DECL_IN_SYSTEM_HEADER (fn)
|| global_dc->dc_warn_system_headers))
{
- temp_override<bool> s (global_dc->dc_warn_system_headers, true);
+ auto s = make_temp_override (global_dc->dc_warn_system_headers, true);
auto_diagnostic_group d;
if (warning (OPT_Wnoexcept, "noexcept-expression evaluates to %<false%> "
"because of a call to %qD", fn))
bool is_unnamed = false;
tree underlying_type = NULL_TREE;
cp_token *type_start_token = NULL;
- temp_override<bool> cleanup (parser->colon_corrects_to_scope_p, false);
+ auto cleanup = make_temp_override (parser->colon_corrects_to_scope_p, false);
/* Parse tentatively so that we can back up if we don't find a
enum-specifier. */
cp_token *token;
bool ellipsis_p;
- temp_override<bool> cleanup
+ auto cleanup = make_temp_override
(parser->auto_is_implicit_function_template_parm_p);
if (!processing_specialization
{
tree attributes = NULL_TREE;
- temp_override<bool> cleanup
+ auto cleanup = make_temp_override
(parser->auto_is_implicit_function_template_parm_p, false);
while (true)
tree attribute, attr_id = NULL_TREE, arguments;
cp_token *token;
- temp_override<bool> cleanup
+ auto cleanup = make_temp_override
(parser->auto_is_implicit_function_template_parm_p, false);
/* First, parse name of the attribute, a.k.a attribute-token. */