On Wed, May 19, 2021 at 12:33 PM Jonathan Wakely via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> This adds new warning flags, enabled by default: -Wc++11-extensions,
> -Wc++14-extensions, -Wc++17-extensions, and -Wc++20-extensions. The
> names of the flags are copied from Clang, which already has similar
> options.
>
> No new diagnostics are added, but the new OPT_Wxxx variables are used to
> control existing pedwarns about occurences of new C++ constructs in code
> using an old C++ standard dialect. This allows several existing warnings
> that cannot currently be disabled to be controlled by the appropriate
> -Wno-xxx flag. For example, it will now be possible to disable warnings
> about using variadic templates in C++98 code, by using the new
> -Wno-c++11-extensions option. This will allow libstdc++ headers to
> disable those warnings unconditionally by using diagnostic pragmas, so
> that they are not emitted even if -Wsystem-headers is used.
>
> Some of the affected diagnostics are currently only given when
> -Wpedantic is used. Now that we have a more specific warning flag, we
> could consider making them not depend on -Wpedantic, and only on the new
> flag. This patch does not do that, as it intends to make no changes to
> what is accepted/rejected by default. The only effect should be that
> the new option is shown when -fdiagnostics-show-option is active, and
> that some warnings can be disabled by using the new flags (and for the
> warnings that previously only dependend on -Wpedantic, it will now be
> possible to disable just those warnings while still using -Wpedantic for
> its other benefits).
>
> A new helper function, warn_about_dialect_p, is introduced to avoid the
> repetition of `if (cxx_dialect < cxxNN && warn_cxxNN_extensions)`
> everywhere.
>
> gcc/c-family/ChangeLog:
>
>         * c.opt (Wc++11-extensions, Wc++14-extensions)
>         (Wc++17-extensions, Wc++20-extensions): New options.
>
> gcc/cp/ChangeLog:
>
>         * call.c (maybe_warn_array_conv): Use new function and option.
>         * cp-tree.h (warn_about_dialect_p): Declare new function.
>         * error.c (maybe_warn_cpp0x): Use new function and options.
>         (warn_about_dialect_p): Define new function.
>         * parser.c (cp_parser_unqualified_id): Use new function and
>         option.
>         (cp_parser_pseudo_destructor_name): Likewise.
>         (cp_parser_lambda_introducer): Likewise.
>         (cp_parser_lambda_declarator_opt): Likewise.
>         (cp_parser_init_statement): Likewise.
>         (cp_parser_decomposition_declaration): Likewise.
>         (cp_parser_function_specifier_opt): Likewise.
>         (cp_parser_static_assert): Likewise.
>         (cp_parser_namespace_definition): Likewise.
>         (cp_parser_initializer_list): Likewise.
>         (cp_parser_member_declaration): Likewise.
>         * pt.c (check_template_variable): Likewise.
>
> Tested x86_64-linux. OK for trunk?
>
>

Thank you for doing this! One thing I'm wondering about, is that I'm
pretty sure clang also allows at least some of these to be used with
plain C as well, for example for things like the old use of "auto" in
C conflicting with the newer C++11 meaning of "auto". Would it be
possible to do likewise for GCC as well? Just an idea.
Thanks,
Eric Gallager

Reply via email to