As I recently threatened, it's time we let -fdeduce-init-list go. This patch removes the implementation while keeping the option for backward compatibility.
Bootstrapped/regtested on x86_64-linux, ok for trunk? 2019-09-03 Marek Polacek <pola...@redhat.com> * c.opt (fdeduce-init-list): Ignored. * call.c (build_over_call): Remove -fdeduce-init-list implementation. * pt.c (unify): Likewise. * doc/invoke.texi: Remove -fdeduce-init-list documentation. * g++.dg/cpp0x/initlist-deduce.C: New test. diff --git gcc/c-family/c.opt gcc/c-family/c.opt index f8a1a1dbdad..9e800ad965d 100644 --- gcc/c-family/c.opt +++ gcc/c-family/c.opt @@ -1456,8 +1456,8 @@ C ObjC C++ ObjC++ Emit debug annotations during preprocessing. fdeduce-init-list -C++ ObjC++ Var(flag_deduce_init_list) Init(0) --fdeduce-init-list enable deduction of std::initializer_list for a template type parameter from a brace-enclosed initializer-list. +C++ ObjC++ Ignore +Does nothing. Preserved for backward compatibility. fdeclone-ctor-dtor C++ ObjC++ Var(flag_declone_ctor_dtor) Init(-1) diff --git gcc/cp/call.c gcc/cp/call.c index 01a25ad6e1e..c3045d948c5 100644 --- gcc/cp/call.c +++ gcc/cp/call.c @@ -8337,38 +8337,6 @@ build_over_call (struct z_candidate *cand, int flags, tsubst_flags_t complain) && !(flags & LOOKUP_EXPLICIT_TMPL_ARGS)) conversion_warning = false; - /* Warn about initializer_list deduction that isn't currently in the - working draft. */ - if (cxx_dialect > cxx98 - && flag_deduce_init_list - && cand->template_decl - && is_std_init_list (non_reference (type)) - && BRACE_ENCLOSED_INITIALIZER_P (arg)) - { - tree tmpl = TI_TEMPLATE (cand->template_decl); - tree realparm = chain_index (j, DECL_ARGUMENTS (cand->fn)); - tree patparm = get_pattern_parm (realparm, tmpl); - tree pattype = TREE_TYPE (patparm); - if (PACK_EXPANSION_P (pattype)) - pattype = PACK_EXPANSION_PATTERN (pattype); - pattype = non_reference (pattype); - - if (TREE_CODE (pattype) == TEMPLATE_TYPE_PARM - && (cand->explicit_targs == NULL_TREE - || (TREE_VEC_LENGTH (cand->explicit_targs) - <= TEMPLATE_TYPE_IDX (pattype)))) - { - pedwarn (input_location, 0, "deducing %qT as %qT", - non_reference (TREE_TYPE (patparm)), - non_reference (type)); - pedwarn (DECL_SOURCE_LOCATION (cand->fn), 0, - " in call to %qD", cand->fn); - pedwarn (input_location, 0, - " (you can disable this with " - "%<-fno-deduce-init-list%>)"); - } - } - /* Set user_conv_p on the argument conversions, so rvalue/base handling knows not to allow any more UDCs. This needs to happen after we process cand->warnings. */ diff --git gcc/cp/pt.c gcc/cp/pt.c index 187f9d857bc..15cc4b20a41 100644 --- gcc/cp/pt.c +++ gcc/cp/pt.c @@ -22073,11 +22073,6 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict, unsigned i; tree orig_parm = parm; - /* Replace T with std::initializer_list<T> for deduction. */ - if (TREE_CODE (parm) == TEMPLATE_TYPE_PARM - && flag_deduce_init_list) - parm = listify (parm); - if (!is_std_init_list (parm) && TREE_CODE (parm) != ARRAY_TYPE) /* We can only deduce from an initializer list argument if the diff --git gcc/doc/invoke.texi gcc/doc/invoke.texi index 2e353be433c..7e359e6beb0 100644 --- gcc/doc/invoke.texi +++ gcc/doc/invoke.texi @@ -2549,28 +2549,6 @@ of a loop too many expressions need to be evaluated, the resulting constexpr evaluation might take too long. The default is 33554432 (1<<25). -@item -fdeduce-init-list -@opindex fdeduce-init-list -Enable deduction of a template type parameter as -@code{std::initializer_list} from a brace-enclosed initializer list, i.e.@: - -@smallexample -template <class T> auto forward(T t) -> decltype (realfn (t)) -@{ - return realfn (t); -@} - -void f() -@{ - forward(@{1,2@}); // call forward<std::initializer_list<int>> -@} -@end smallexample - -This deduction was implemented as a possible extension to the -originally proposed semantics for the C++11 standard, but was not part -of the final standard, so it is disabled by default. This option is -deprecated, and may be removed in a future version of G++. - @item -fno-elide-constructors @opindex fno-elide-constructors @opindex felide-constructors diff --git gcc/testsuite/g++.dg/cpp0x/initlist-deduce.C gcc/testsuite/g++.dg/cpp0x/initlist-deduce.C index 6ae32a6c55d..59d98ef6dda 100644 --- gcc/testsuite/g++.dg/cpp0x/initlist-deduce.C +++ gcc/testsuite/g++.dg/cpp0x/initlist-deduce.C @@ -1,9 +1,4 @@ -// Test for deduction of T as std::initializer_list. This isn't currently -// supported by the working draft, but is necessary for perfect forwarding -// of initializer-lists to things that can take a std::initializer_list. - -// { dg-options "-fdeduce-init-list" } -// { dg-do run { target c++11 } } +// { dg-do compile { target c++11 } } #include <initializer_list> @@ -15,14 +10,13 @@ struct A void f (A a) { } template <class T> -auto g (T&& t) -> decltype (f(t)) // { dg-warning "call" } +auto g (T&& t) -> decltype (f(t)) { return f(t); } int main() { - g({1}); // { dg-warning "deduc" } + g({1}); // { dg-error "no matching function" } } -// { dg-prune-output "-fno-deduce-init-list" }