public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/101582] New: C++ FE doesn't accept attribute-declaration
@ 2021-07-22 15:29 jakub at gcc dot gnu.org
  2021-07-22 17:32 ` [Bug c++/101582] " jakub at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-07-22 15:29 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 101582
           Summary: C++ FE doesn't accept attribute-declaration
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jakub at gcc dot gnu.org
  Target Milestone: ---

[[]];

is rejected by gcc (accepted by clang) in C++11 and later mode:
error: declaration does not declare anything [-fpermissive]

It is fine to warn about attributes we don't handle and throw away, like we
e.g.
on empty statements with attributes warn
attributes at the beginning of statement are ignored [-Wattributes]
except for the few like [[fallthrough]] or [[cold]], but we shouldn't reject it
with permerror.

I'll need it for OpenMP directives in attributes...

Implementation-wise, I think one option is in cp_parser_toplevel_declaration
after the
  else if (token->type == CPP_SEMICOLON)
    {
      cp_lexer_consume_token (parser->lexer);
      /* A declaration consisting of a single semicolon is invalid
       * before C++11.  Allow it unless we're being pedantic.  */
      if (cxx_dialect < cxx11)
        pedwarn (input_location, OPT_Wpedantic, "extra %<;%>");
    }
case try cp_parser_skip_std_attribute_spec_seq and if the token after it
is CPP_SEMICOLON, handle it as attribute-declaration, or faster but less clean
grammar-wise in cp_parser_simple_declaration detect the case where we have only
std attributes followed by semicolon and handle it there.

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

* [Bug c++/101582] C++ FE doesn't accept attribute-declaration
  2021-07-22 15:29 [Bug c++/101582] New: C++ FE doesn't accept attribute-declaration jakub at gcc dot gnu.org
@ 2021-07-22 17:32 ` jakub at gcc dot gnu.org
  2021-07-22 21:28 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-07-22 17:32 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |jakub at gcc dot gnu.org
   Last reconfirmed|                            |2021-07-22
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |ASSIGNED

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 51198
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51198&action=edit
gcc12-pr101582.patch

Untested fix.

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

* [Bug c++/101582] C++ FE doesn't accept attribute-declaration
  2021-07-22 15:29 [Bug c++/101582] New: C++ FE doesn't accept attribute-declaration jakub at gcc dot gnu.org
  2021-07-22 17:32 ` [Bug c++/101582] " jakub at gcc dot gnu.org
@ 2021-07-22 21:28 ` pinskia at gcc dot gnu.org
  2021-07-30  8:34 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-22 21:28 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |aaron.ballman+gcc at gmail dot com

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 87456 has been marked as a duplicate of this bug. ***

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

* [Bug c++/101582] C++ FE doesn't accept attribute-declaration
  2021-07-22 15:29 [Bug c++/101582] New: C++ FE doesn't accept attribute-declaration jakub at gcc dot gnu.org
  2021-07-22 17:32 ` [Bug c++/101582] " jakub at gcc dot gnu.org
  2021-07-22 21:28 ` pinskia at gcc dot gnu.org
@ 2021-07-30  8:34 ` cvs-commit at gcc dot gnu.org
  2021-07-30  8:34 ` jakub at gcc dot gnu.org
  2021-12-07 19:38 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-07-30  8:34 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:77ab4e3be2d92b1ff671d58418d852195f10dd20

commit r12-2607-g77ab4e3be2d92b1ff671d58418d852195f10dd20
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Jul 30 10:30:16 2021 +0200

    c++: Accept C++11 attribute-definition [PR101582]

    As the following testcase shows, we don't parse properly
    C++11 attribute-declaration:
    https://eel.is/c++draft/dcl.dcl#nt:attribute-declaration

    cp_parser_toplevel_declaration just handles empty-declaration parsing
    (with diagnostics for C++98) and otherwise calls cp_parser_declaration
    which on it calls cp_parser_simple_declaration and rejects it with
    "does not declare anything" permerror.

    The following patch moves the handling of empty-declaration from
    cp_parser_toplevel_declaration to cp_parser_declaration and
    handles attribute-declaration in cp_parser_declaration
    by parsing the attributes (standard ones only, we've never supported
    __attribute__((...)); at namespace scope, so I'm not sure we need to
    introduce that), which for C++98 emits the needed diagnostics, and then
    warning if there are any attributes that we throw away on the floor.

    I'll need this later for OpenMP directives at namespace scope, e.g.
    [[omp::directive (requires, atomic_default_mem_order(seq_cst))]];
    should be valid at namespace scope (and many other directives).

    2021-07-30  Jakub Jelinek  <jakub@redhat.com>

            PR c++/101582
            * parser.c (cp_parser_skip_std_attribute_spec_seq): Add a forward
            declaration.
            (cp_parser_declaration): Parse empty-declaration and
            attribute-declaration.
            (cp_parser_toplevel_declaration): Don't parse empty-declaration
here.

            * g++.dg/cpp0x/gen-attrs-45.C: Expect a warning about ignored
            attributes instead of error.
            * g++.dg/cpp0x/gen-attrs-75.C: New test.
            * g++.dg/modules/pr101582-1.C: New test.

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

* [Bug c++/101582] C++ FE doesn't accept attribute-declaration
  2021-07-22 15:29 [Bug c++/101582] New: C++ FE doesn't accept attribute-declaration jakub at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2021-07-30  8:34 ` cvs-commit at gcc dot gnu.org
@ 2021-07-30  8:34 ` jakub at gcc dot gnu.org
  2021-12-07 19:38 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-07-30  8:34 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

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

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed.

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

* [Bug c++/101582] C++ FE doesn't accept attribute-declaration
  2021-07-22 15:29 [Bug c++/101582] New: C++ FE doesn't accept attribute-declaration jakub at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2021-07-30  8:34 ` jakub at gcc dot gnu.org
@ 2021-12-07 19:38 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-07 19:38 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |12.0
           Keywords|                            |rejects-valid

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

end of thread, other threads:[~2021-12-07 19:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-22 15:29 [Bug c++/101582] New: C++ FE doesn't accept attribute-declaration jakub at gcc dot gnu.org
2021-07-22 17:32 ` [Bug c++/101582] " jakub at gcc dot gnu.org
2021-07-22 21:28 ` pinskia at gcc dot gnu.org
2021-07-30  8:34 ` cvs-commit at gcc dot gnu.org
2021-07-30  8:34 ` jakub at gcc dot gnu.org
2021-12-07 19:38 ` pinskia 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).