[PATCH] c++: Implement C++26 P3176R1 - The Oxford variadic comma
Marek Polacek
polacek@redhat.com
Mon Nov 25 20:40:18 GMT 2024
On Mon, Nov 25, 2024 at 07:21:03PM +0100, Jakub Jelinek wrote:
> Hi!
>
> While we are already in stage3, I wonder if implementing this small paper
> wouldn't be useful even for GCC 15, so that we have in the GCC world one
> extra year of deprecation of variadic ellipsis without preceding comma.
>
> The paper just deprecates something, I'd hope most of the C++ code in the
> wild when it uses variadic functions at all uses the comma before the
> ellipsis.
>
> So far smoke tested (make check-g++ over all language variants,
> make check in libstdc++), ok for trunk if it passes full bootstrap/regtest?
>
> 2024-11-25 Jakub Jelinek <jakub@redhat.com>
>
> gcc/c-family/
> * c.opt: Implement C++26 P3176R1 - The Oxford variadic comma.
> (Wdeprecated-variadic-comma-omission): New option.
> * c.opt.urls: Regenerate.
> * c-opts.cc (c_common_post_options): Default to
> -Wdeprecated-variadic-comma-omission for C++26 or -Wpedantic.
> gcc/cp/
> * parser.cc (cp_parser_parameter_declaration_clause): Emit
> -Wdeprecated-variadic-comma-omission warnings.
> gcc/
> * doc/invoke.texi (-Wdeprecated-variadic-comma-omission): Document.
> gcc/testsuite/
> * g++.dg/cpp26/variadic-comma1.C: New test.
> * g++.dg/cpp26/variadic-comma2.C: New test.
> * g++.dg/cpp1z/fold10.C: Expect a warning for C++26.
> * g++.dg/ext/attrib33.C: Likewise.
> * g++.dg/cpp1y/lambda-generic-variadic19.C: Likewise.
> * g++.dg/cpp2a/lambda-generic10.C: Likewise.
> * g++.dg/cpp0x/lambda/lambda-const3.C: Likewise.
> * g++.dg/cpp0x/variadic164.C: Likewise.
> * g++.dg/cpp0x/variadic17.C: Likewise.
> * g++.dg/cpp0x/udlit-args-neg.C: Likewise.
> * g++.dg/cpp0x/variadic28.C: Likewise.
> * g++.dg/cpp0x/gen-attrs-33.C: Likewise.
> * g++.dg/cpp23/explicit-obj-diagnostics3.C: Likewise.
> * g++.old-deja/g++.law/operators15.C: Likewise.
> * g++.old-deja/g++.mike/p811.C: Likewise.
> * g++.old-deja/g++.mike/p12306.C (printf): Add , before ... .
> * g++.dg/analyzer/fd-bind-pr107783.C (bind): Likewise.
> * g++.dg/cpp0x/vt-65790.C (printf): Likewise.
> libstdc++-v3/
> * include/std/functional (_Bind_check_arity): Add , before ... .
> * include/bits/refwrap.h (_Mem_fn_traits, _Weak_result_type_impl):
> Likewise.
> * include/tr1/type_traits (is_function): Likewise.
>
> --- gcc/c-family/c.opt.jj 2024-11-22 19:52:19.477579338 +0100
> +++ gcc/c-family/c.opt 2024-11-25 16:22:11.325028058 +0100
> @@ -672,6 +672,10 @@ Wdeprecated-non-prototype
> C ObjC Var(warn_deprecated_non_prototype) Init(-1) Warning
> Warn about calls with arguments to functions declared without parameters.
>
> +Wdeprecated-variadic-comma-omission
> +C++ ObjC++ Var(warn_deprecated_variadic_comma_omission) Warning
> +Warn about deprecated omission of comma before ... in variadic function declaration.
> +
> Wdesignated-init
> C ObjC Var(warn_designated_init) Init(1) Warning
> Warn about positional initialization of structs requiring designated initializers.
> --- gcc/c-family/c.opt.urls.jj 2024-11-18 21:59:35.872150269 +0100
> +++ gcc/c-family/c.opt.urls 2024-11-25 17:38:25.396693802 +0100
> @@ -310,6 +310,9 @@ UrlSuffix(gcc/C_002b_002b-Dialect-Option
> Wdeprecated-non-prototype
> UrlSuffix(gcc/Warning-Options.html#index-Wdeprecated-non-prototype)
>
> +Wdeprecated-variadic-comma-omission
> +UrlSuffix(gcc/C_002b_002b-Dialect-Options.html#index-Wdeprecated-variadic-comma-omission)
> +
> Wdesignated-init
> UrlSuffix(gcc/Warning-Options.html#index-Wdesignated-init)
>
> --- gcc/c-family/c-opts.cc.jj 2024-11-23 13:00:28.188030262 +0100
> +++ gcc/c-family/c-opts.cc 2024-11-25 16:23:36.569829016 +0100
> @@ -1051,6 +1051,11 @@ c_common_post_options (const char **pfil
> warn_deprecated_literal_operator,
> deprecated_in (cxx23));
>
> + /* -Wdeprecated-variadic-comma-omission is enabled by default in C++26. */
> + SET_OPTION_IF_UNSET (&global_options, &global_options_set,
> + warn_deprecated_variadic_comma_omission,
> + deprecated_in (cxx26));
> +
> /* -Wtemplate-id-cdtor is enabled by default in C++20. */
> SET_OPTION_IF_UNSET (&global_options, &global_options_set,
> warn_template_id_cdtor,
> --- gcc/cp/parser.cc.jj 2024-11-23 13:00:29.060017680 +0100
> +++ gcc/cp/parser.cc 2024-11-25 17:02:24.551059305 +0100
> @@ -25667,6 +25667,16 @@ cp_parser_parameter_declaration_clause (
> omitted. */
> else if (token->type == CPP_ELLIPSIS)
> {
> + /* Deprecated by P3176R1 in C++26. */
> + if (warn_deprecated_variadic_comma_omission)
> + {
> + gcc_rich_location richloc (token->location);
> + richloc.add_fixit_insert_before (", ");
> + warning_at (&richloc, OPT_Wdeprecated_variadic_comma_omission,
> + "omitting of %<,%> before variadic %<...%> is "
> + "deprecated in C++26");
> + }
> +
> /* Consume the `...' token. */
> cp_lexer_consume_token (parser->lexer);
> /* And remember that we saw it. */
> --- gcc/doc/invoke.texi.jj 2024-11-25 09:32:32.508139851 +0100
> +++ gcc/doc/invoke.texi 2024-11-25 17:23:57.269904929 +0100
> @@ -4081,6 +4081,22 @@ string operator "" _i18n(const char*, st
> string operator ""_i18n(const char*, std::size_t); // preferred
> @end smallexample
>
> +@opindex Wdeprecated-variadic-comma-omission
> +@opindex Wno-deprecated-variadic-comma-omission
> +@item -Wdeprecated-variadic-comma-omission @r{(C++ and Objective-C++ only)}
> +Warn that omitting of a comma before the variadic @code{...} at the end of
Just "omitting a comma", I think.
> +function parameter list is deprecated. This warning is enabled by
"of a function parameter list"
I suppose we should also test -Wno-deprecated and/or
-Wno-deprecated-variadic-comma-omission in C++26.
Otherwise the patch LGTM, thanks.
Marek
More information about the Libstdc++
mailing list