public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/101940] New: Implement -fignored-attributes
@ 2021-08-16 21:05 mpolacek at gcc dot gnu.org
  2021-08-17  7:48 ` [Bug c++/101940] " rguenth at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-08-16 21:05 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101940

            Bug ID: 101940
           Summary: Implement -fignored-attributes
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mpolacek at gcc dot gnu.org
  Target Milestone: ---

It is desirable for -Wattributes to warn about e.g.

[[deprecate]] void g(); // typo, should warn

However, -Wattributes also warns about vendor-specific attributes (that's
because lookup_scoped_attribute_spec -> find_attribute_namespace finds
nothing), which, with -Werror, causes grief.  We don't want the -Wattributes
warning for

[[company::attr]] void f();

GCC warns because it doesn't know the "company" namespace; it only knows the
"gnu" and "omp" namespaces.  We could entirely disable warning about attributes
in unknown scopes but then the compiler would also miss typos like

  [[company::attrx]] void f();

or 

  [[gmu::warn_used_result]] int write();

so that is not a viable solution.  A workaround is to use a #pragma:

  #pragma GCC diagnostic push
  #pragma GCC diagnostic ignored "-Wattributes"
  [[company::attr]] void f() {}
  #pragma GCC diagnostic pop

but that's a mouthful and awkward to use and could also hide typos.  In fact,
any macro-based solution doesn't seem like a way forward.

So this RFE asks for -fignored-attributes=, which, IMHO, should take these
arguments:

company::attr
company::
clang

the last is a special option to ignore clang-only attributes.  Maybe we could
also accept ::attr.

This option should go well with using @file: we could have a file containing
-fignored-attributes=vendor::attr1,vendor::attr2
and then invoke gcc with '@attrs' or similar.

It might also make sense to implement a #pragma to go along:

#pragma GCC ignored-attributes=vendor::attr1,vendor::attr2.

This should help with various static analysis tools and similar.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/101940] Implement -fignored-attributes
  2021-08-16 21:05 [Bug c++/101940] New: Implement -fignored-attributes mpolacek at gcc dot gnu.org
@ 2021-08-17  7:48 ` rguenth at gcc dot gnu.org
  2021-08-17 14:19 ` mpolacek at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-08-17  7:48 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101940

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|unknown                     |12.0

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Or -Wno-attributes=company:: just like we have -Wno-error=subdiag?

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/101940] Implement -fignored-attributes
  2021-08-16 21:05 [Bug c++/101940] New: Implement -fignored-attributes mpolacek at gcc dot gnu.org
  2021-08-17  7:48 ` [Bug c++/101940] " rguenth at gcc dot gnu.org
@ 2021-08-17 14:19 ` mpolacek at gcc dot gnu.org
  2021-08-17 15:31 ` msebor at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-08-17 14:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101940

--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Possibly.  I thought I'd rather keep the names of the option and pragma the
same, but maybe that's not necessary.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/101940] Implement -fignored-attributes
  2021-08-16 21:05 [Bug c++/101940] New: Implement -fignored-attributes mpolacek at gcc dot gnu.org
  2021-08-17  7:48 ` [Bug c++/101940] " rguenth at gcc dot gnu.org
  2021-08-17 14:19 ` mpolacek at gcc dot gnu.org
@ 2021-08-17 15:31 ` msebor at gcc dot gnu.org
  2021-08-17 15:49 ` mpolacek at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-08-17 15:31 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101940

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |msebor at gcc dot gnu.org
   Last reconfirmed|                            |2021-08-17
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

--- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> ---
If the only thing the new option is meant to control is -Wattributes warnings I
tend to agree that adding an optional argument to -Wattributes= would be a
natural enhancement. (Similar to -Wnormalized= or -Wsuggest-attribute= except
with a free-form string as an argument).  I would expect the existing
diagnostic pragmas to work with it too:

#pragma GCC ignored "-Wattributes=vendor::attr1"

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/101940] Implement -fignored-attributes
  2021-08-16 21:05 [Bug c++/101940] New: Implement -fignored-attributes mpolacek at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2021-08-17 15:31 ` msebor at gcc dot gnu.org
@ 2021-08-17 15:49 ` mpolacek at gcc dot gnu.org
  2021-09-20 17:07 ` [Bug c++/101940] Implement -Wno-attributes=vendor::attr mpolacek at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-08-17 15:49 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101940

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |mpolacek at gcc dot gnu.org

--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Good point, I like that!

So, mine, I guess.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/101940] Implement -Wno-attributes=vendor::attr
  2021-08-16 21:05 [Bug c++/101940] New: Implement -fignored-attributes mpolacek at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2021-08-17 15:49 ` mpolacek at gcc dot gnu.org
@ 2021-09-20 17:07 ` mpolacek at gcc dot gnu.org
  2021-11-10 14:26 ` cvs-commit at gcc dot gnu.org
  2021-11-10 14:31 ` mpolacek at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-09-20 17:07 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101940

--- Comment #5 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Patch posted:
https://gcc.gnu.org/pipermail/gcc-patches/2021-September/579858.html

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/101940] Implement -Wno-attributes=vendor::attr
  2021-08-16 21:05 [Bug c++/101940] New: Implement -fignored-attributes mpolacek at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2021-09-20 17:07 ` [Bug c++/101940] Implement -Wno-attributes=vendor::attr mpolacek at gcc dot gnu.org
@ 2021-11-10 14:26 ` cvs-commit at gcc dot gnu.org
  2021-11-10 14:31 ` mpolacek at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-11-10 14:26 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101940

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:a1ad0d84d7fcbcaa7a697290387b911eb7e1bd46

commit r12-5123-ga1ad0d84d7fcbcaa7a697290387b911eb7e1bd46
Author: Marek Polacek <polacek@redhat.com>
Date:   Thu Sep 9 09:17:27 2021 -0400

    attribs: Implement -Wno-attributes=vendor::attr [PR101940]

    It is desirable for -Wattributes to warn about e.g.

    [[deprecate]] void g(); // typo, should warn

    However, -Wattributes also warns about vendor-specific attributes
    (that's because lookup_scoped_attribute_spec -> find_attribute_namespace
    finds nothing), which, with -Werror, causes grief.  We don't want the
    -Wattributes warning for

    [[company::attr]] void f();

    GCC warns because it doesn't know the "company" namespace; it only knows
    the "gnu" and "omp" namespaces.  We could entirely disable warning about
    attributes in unknown scopes but then the compiler would also miss typos
    like

      [[company::attrx]] void f();

    or

      [[gmu::warn_used_result]] int write();

    so that is not a viable solution.  A workaround is to use a #pragma:

      #pragma GCC diagnostic push
      #pragma GCC diagnostic ignored "-Wattributes"
      [[company::attr]] void f() {}
      #pragma GCC diagnostic pop

    but that's a mouthful and awkward to use and could also hide typos.  In
    fact, any macro-based solution doesn't seem like a way forward.

    This patch implements -Wno-attributes=, which takes these arguments:

    company::attr
    company::

    This option should go well with using @file: the user could have a file
    containing
    -Wno-attributes=vendor::attr1,vendor::attr2
    and then invoke gcc with '@attrs' or similar.

    I've also added a new pragma which has the same effect:

    The pragma along with the new option should help with various static
    analysis tools.

            PR c++/101940

    gcc/ChangeLog:

            * attribs.c (struct scoped_attributes): Add a bool member.
            (lookup_scoped_attribute_spec): Forward declare.
            (register_scoped_attributes): New bool parameter, defaulted to
            false.  Use it.
            (handle_ignored_attributes_option): New function.
            (free_attr_data): New function.
            (init_attributes): Call handle_ignored_attributes_option.
            (attr_namespace_ignored_p): New function.
            (decl_attributes): Check attr_namespace_ignored_p before
            warning.
            * attribs.h (free_attr_data): Declare.
            (register_scoped_attributes): Adjust declaration.
            (handle_ignored_attributes_option): Declare.
            (canonicalize_attr_name): New function template.
            (canonicalize_attr_name): Use it.
            * common.opt (Wattributes=): New option with a variable.
            * doc/extend.texi: Document #pragma GCC diagnostic
ignored_attributes.
            * doc/invoke.texi: Document -Wno-attributes=.
            * opts.c (common_handle_option) <case OPT_Wattributes_>: Handle.
            * plugin.h (register_scoped_attributes): Adjust declaration.
            * toplev.c (compile_file): Call free_attr_data.

    gcc/c-family/ChangeLog:

            * c-pragma.c (handle_pragma_diagnostic): Handle #pragma GCC
diagnostic
            ignored_attributes.

    gcc/testsuite/ChangeLog:

            * c-c++-common/Wno-attributes-1.c: New test.
            * c-c++-common/Wno-attributes-2.c: New test.
            * c-c++-common/Wno-attributes-3.c: New test.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/101940] Implement -Wno-attributes=vendor::attr
  2021-08-16 21:05 [Bug c++/101940] New: Implement -fignored-attributes mpolacek at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2021-11-10 14:26 ` cvs-commit at gcc dot gnu.org
@ 2021-11-10 14:31 ` mpolacek at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-11-10 14:31 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101940

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #7 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Implemented in GCC 12.  Will update changes.html.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-11-10 14:31 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-16 21:05 [Bug c++/101940] New: Implement -fignored-attributes mpolacek at gcc dot gnu.org
2021-08-17  7:48 ` [Bug c++/101940] " rguenth at gcc dot gnu.org
2021-08-17 14:19 ` mpolacek at gcc dot gnu.org
2021-08-17 15:31 ` msebor at gcc dot gnu.org
2021-08-17 15:49 ` mpolacek at gcc dot gnu.org
2021-09-20 17:07 ` [Bug c++/101940] Implement -Wno-attributes=vendor::attr mpolacek at gcc dot gnu.org
2021-11-10 14:26 ` cvs-commit at gcc dot gnu.org
2021-11-10 14:31 ` mpolacek at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).