[C++ PATCH] Don't pedwarn on deprecated or fallthrough attributes (PR c++/79301)
Jason Merrill
jason@redhat.com
Wed Feb 15 16:23:00 GMT 2017
OK.
On Fri, Feb 10, 2017 at 2:53 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> The reporter complained that even when __has_cpp_attribute (fallthrough)
> and similarly __has_cpp_attribute (deprecated) return true, in pedantic
> mode the compiler will error out on those.
>
> The following patch just removes the pedwarn, i.e. we accept those
> attributes as extensions even in C++11 and C++14 modes.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
>
> 2017-02-10 Jakub Jelinek <jakub@redhat.com>
>
> PR c++/79301
> * parser.c (cp_parser_std_attribute): Don't pedwarn about
> [[deprecated]] with -std=c++11 and [[fallthrough]] with
> -std=c++11 and -std=c++14.
>
> * g++.dg/cpp1y/feat-cxx11-neg.C: Remove (with pedwarn) from
> [[deprecated]] comment.
> * g++.dg/cpp1y/feat-cxx98-neg.C: Likewise.
> * g++.dg/cpp1y/feat-cxx11.C: Likewise.
> * g++.dg/cpp1y/attr-deprecated-neg.C: Don't expect warnings for
> [[deprecated]] in -std=c++11.
> * g++.dg/cpp0x/fallthrough2.C: Don't expect warnings for
> [[fallthrough]] in -std=c++11 and -std=c++14.
>
> --- gcc/cp/parser.c.jj 2017-02-09 23:01:49.000000000 +0100
> +++ gcc/cp/parser.c 2017-02-10 17:24:15.860948212 +0100
> @@ -24747,22 +24747,10 @@ cp_parser_std_attribute (cp_parser *pars
> TREE_PURPOSE (TREE_PURPOSE (attribute)) = get_identifier ("gnu");
> /* C++14 deprecated attribute is equivalent to GNU's. */
> else if (is_attribute_p ("deprecated", attr_id))
> - {
> - if (cxx_dialect == cxx11)
> - pedwarn (token->location, OPT_Wpedantic,
> - "%<deprecated%> is a C++14 feature;"
> - " use %<gnu::deprecated%>");
> - TREE_PURPOSE (TREE_PURPOSE (attribute)) = get_identifier ("gnu");
> - }
> + TREE_PURPOSE (TREE_PURPOSE (attribute)) = get_identifier ("gnu");
> /* C++17 fallthrough attribute is equivalent to GNU's. */
> else if (is_attribute_p ("fallthrough", attr_id))
> - {
> - if (cxx_dialect < cxx1z)
> - pedwarn (token->location, OPT_Wpedantic,
> - "%<fallthrough%> is a C++17 feature;"
> - " use %<gnu::fallthrough%>");
> - TREE_PURPOSE (TREE_PURPOSE (attribute)) = get_identifier ("gnu");
> - }
> + TREE_PURPOSE (TREE_PURPOSE (attribute)) = get_identifier ("gnu");
> /* Transactional Memory TS optimize_for_synchronized attribute is
> equivalent to GNU transaction_callable. */
> else if (is_attribute_p ("optimize_for_synchronized", attr_id))
> --- gcc/testsuite/g++.dg/cpp1y/feat-cxx11-neg.C.jj 2015-10-11 19:11:09.000000000 +0200
> +++ gcc/testsuite/g++.dg/cpp1y/feat-cxx11-neg.C 2017-02-10 17:28:32.637566582 +0100
> @@ -57,7 +57,7 @@
>
> // C++14 attributes:
>
> -// Attribute [[deprecated]] is allowed in C++11 as an extension (with pedwarn).
> +// Attribute [[deprecated]] is allowed in C++11 as an extension.
> //#ifdef __has_cpp_attribute
> //# if __has_cpp_attribute(deprecated) == 201309
> //# error "__has_cpp_attribute(deprecated)" // { }
> --- gcc/testsuite/g++.dg/cpp1y/feat-cxx98-neg.C.jj 2016-07-07 20:40:27.000000000 +0200
> +++ gcc/testsuite/g++.dg/cpp1y/feat-cxx98-neg.C 2017-02-10 17:29:46.592592629 +0100
> @@ -144,7 +144,7 @@
>
> // C++14 attributes:
>
> -// Attribute [[deprecated]] is allowed in C++11 as an extension (with pedwarn).
> +// Attribute [[deprecated]] is allowed in C++11 as an extension.
> //#ifdef __has_cpp_attribute
> //# if __has_cpp_attribute(deprecated) == 201309
> //# error "__has_cpp_attribute(deprecated)" // { }
> --- gcc/testsuite/g++.dg/cpp1y/feat-cxx11.C.jj 2016-11-03 22:03:27.000000000 +0100
> +++ gcc/testsuite/g++.dg/cpp1y/feat-cxx11.C 2017-02-10 17:28:45.356399081 +0100
> @@ -166,7 +166,7 @@
>
> // C++14 attributes:
>
> -// Attribute [[deprecated]] is allowed in C++11 as an extension (with pedwarn).
> +// Attribute [[deprecated]] is allowed in C++11 as an extension.
> #ifdef __has_cpp_attribute
> # if ! __has_cpp_attribute(deprecated)
> # error "__has_cpp_attribute(deprecated)"
> --- gcc/testsuite/g++.dg/cpp1y/attr-deprecated-neg.C.jj 2014-10-10 08:19:37.000000000 +0200
> +++ gcc/testsuite/g++.dg/cpp1y/attr-deprecated-neg.C 2017-02-10 17:32:22.592541551 +0100
> @@ -1,22 +1,22 @@
> // { dg-do compile { target c++11_only } }
> // { dg-options "-pedantic" }
>
> -class [[deprecated]] A // { dg-warning "'deprecated' is a C..14 feature" }
> +class [[deprecated]] A // { dg-bogus "'deprecated' is a C..14 feature" }
> {
> };
>
> -[[deprecated]] // { dg-warning "'deprecated' is a C..14 feature" }
> +[[deprecated]] // { dg-bogus "'deprecated' is a C..14 feature" }
> int
> foo(int n)
> {
> return 42 + n;
> }
>
> -class [[deprecated("B has been superceded by C")]] B // { dg-warning "'deprecated' is a C..14 feature" }
> +class [[deprecated("B has been superceded by C")]] B // { dg-bogus "'deprecated' is a C..14 feature" }
> {
> };
>
> -[[deprecated("bar is unsafe; use foobar instead")]] // { dg-warning "'deprecated' is a C..14 feature" }
> +[[deprecated("bar is unsafe; use foobar instead")]] // { dg-bogus "'deprecated' is a C..14 feature" }
> int
> bar(int n)
> {
> --- gcc/testsuite/g++.dg/cpp0x/fallthrough2.C.jj 2016-09-29 22:53:13.000000000 +0200
> +++ gcc/testsuite/g++.dg/cpp0x/fallthrough2.C 2017-02-10 17:33:27.261691517 +0100
> @@ -11,7 +11,7 @@ f (int i)
> {
> case 1:
> bar (1);
> - [[fallthrough]]; // { dg-warning ".fallthrough. is a C\\+\\+17 feature" "" { target { c++14_down } } }
> + [[fallthrough]];
> case 3:
> bar (1);
> [[gnu::fallthrough, gnu::fallthrough]]; // { dg-warning ".fallthrough. attribute specified multiple times" }
>
> Jakub
More information about the Gcc-patches
mailing list