public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/97536] New: [concepts] parser segfault for concept defined in function template
@ 2020-10-23  1:14 hello at josephloser dot com
  2020-10-26 16:49 ` [Bug c++/97536] " mpolacek at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: hello at josephloser dot com @ 2020-10-23  1:14 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 97536
           Summary: [concepts] parser segfault for concept defined in
                    function template
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hello at josephloser dot com
  Target Milestone: ---

The code below causes a segfault when parsing a concept definition inside a
function template. Note that concepts cannot be defined inside a function
scope, so this should result in a useful diagnostic.

Output of compiling the program with -std=c++2a:
prog.cc: In function 'auto foo()':
prog.cc:3:5: warning: C++20 concept definition syntax is 'concept <name> =
<expr>'
    3 |     concept bar = true;
      |     ^~~~~~~
prog.cc:3:13: internal compiler error: Segmentation fault
    3 |     concept bar = true;
      |             ^~~
0xc2e30f crash_signal
        ../../source/gcc/toplev.c:330
0x68c49c grokvardecl
        ../../source/gcc/cp/decl.c:10103
0x68c49c grokdeclarator(cp_declarator const*, cp_decl_specifier_seq*,
decl_context, int, tree_node**)
        ../../source/gcc/cp/decl.c:13691
0x6913c8 start_decl(cp_declarator const*, cp_decl_specifier_seq*, int,
tree_node*, tree_node*, tree_node**)
        ../../source/gcc/cp/decl.c:5218
0x71cc3e cp_parser_init_declarator
        ../../source/gcc/cp/parser.c:20934
0x6fe49c cp_parser_simple_declaration
        ../../source/gcc/cp/parser.c:13876
0x7002ad cp_parser_declaration_statement
        ../../source/gcc/cp/parser.c:13316
0x700e97 cp_parser_statement
        ../../source/gcc/cp/parser.c:11562
0x701e6d cp_parser_statement_seq_opt
        ../../source/gcc/cp/parser.c:11928
0x701f20 cp_parser_compound_statement
        ../../source/gcc/cp/parser.c:11878
0x718d2a cp_parser_function_body
        ../../source/gcc/cp/parser.c:23236
0x718d2a cp_parser_ctor_initializer_opt_and_function_body
        ../../source/gcc/cp/parser.c:23287
0x71c730 cp_parser_function_definition_after_declarator
        ../../source/gcc/cp/parser.c:29182
0x71d64f cp_parser_function_definition_from_specifiers_and_declarator
        ../../source/gcc/cp/parser.c:29098
0x71d64f cp_parser_init_declarator
        ../../source/gcc/cp/parser.c:20838
0x722c14 cp_parser_single_declaration
        ../../source/gcc/cp/parser.c:29669
0x722d77 cp_parser_template_declaration_after_parameters
        ../../source/gcc/cp/parser.c:29242
0x72337a cp_parser_explicit_template_declaration
        ../../source/gcc/cp/parser.c:29507
0x726cd9 cp_parser_declaration
        ../../source/gcc/cp/parser.c:13524
0x72726d cp_parser_translation_unit
        ../../source/gcc/cp/parser.c:4793
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

Wandbox link: https://wandbox.org/permlink/PKqzkXQLl3fv8ev4

For what its worth, the warning given for when a concept is defined inside a
function (not a function template) could probably be improved as well. If you
remove the template on `foo` such that it is just a function, the error is:

prog.cc: In function 'auto foo()':
prog.cc:2:5: warning: C++20 concept definition syntax is 'concept <name> =
<expr>'
    2 |     concept bar = true;
      |     ^~~~~~~
prog.cc:2:5: error: a non-template variable cannot be 'concept'

The error message is fine, but the warning is a bit of a misnomer as `concept
bar = true;` does meet the grammar of `concept <name> = <expr>`.

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

* [Bug c++/97536] [concepts] parser segfault for concept defined in function template
  2020-10-23  1:14 [Bug c++/97536] New: [concepts] parser segfault for concept defined in function template hello at josephloser dot com
@ 2020-10-26 16:49 ` mpolacek at gcc dot gnu.org
  2021-03-30 15:52 ` mpolacek at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-10-26 16:49 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
                 CC|                            |mpolacek at gcc dot gnu.org
   Last reconfirmed|                            |2020-10-26

--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Confirmed.

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

* [Bug c++/97536] [concepts] parser segfault for concept defined in function template
  2020-10-23  1:14 [Bug c++/97536] New: [concepts] parser segfault for concept defined in function template hello at josephloser dot com
  2020-10-26 16:49 ` [Bug c++/97536] " mpolacek at gcc dot gnu.org
@ 2021-03-30 15:52 ` mpolacek at gcc dot gnu.org
  2021-04-19 22:06 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-03-30 15:52 UTC (permalink / raw)
  To: gcc-bugs

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

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 #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Still present, just hit this with

template <typename> void forward() {
  concept C = true;
}

Let me take a look then...

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

* [Bug c++/97536] [concepts] parser segfault for concept defined in function template
  2020-10-23  1:14 [Bug c++/97536] New: [concepts] parser segfault for concept defined in function template hello at josephloser dot com
  2020-10-26 16:49 ` [Bug c++/97536] " mpolacek at gcc dot gnu.org
  2021-03-30 15:52 ` mpolacek at gcc dot gnu.org
@ 2021-04-19 22:06 ` cvs-commit at gcc dot gnu.org
  2021-04-19 22:07 ` mpolacek at gcc dot gnu.org
  2022-01-04  2:20 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-04-19 22:06 UTC (permalink / raw)
  To: gcc-bugs

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

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

https://gcc.gnu.org/g:29d8838c5ecaf70ce552fea7639ec1f34adb2e04

commit r11-8252-g29d8838c5ecaf70ce552fea7639ec1f34adb2e04
Author: Marek Polacek <polacek@redhat.com>
Date:   Mon Apr 19 16:21:46 2021 -0400

    c++: ICE with concept defined in function [PR97536]

    This is an ICE-on-invalid, but I keep seeing it when reducing code so
    I'd like to fix it.  We crash on

      template <typename> void forward() {
        concept C = true;
      }

    which breaks two requirements:
    [temp.concept]/1: A concept is a template ...
    [temp.concept]/3: A concept-definition shall inhabit a namespace scope.

    This patch adds a test that exercises broken code and fixes the ICE
    by checking that a concept-definition is defined at namespace scope.

    gcc/cp/ChangeLog:

            PR c++/97536
            * decl.c (grokvardecl): Given an error when a concept is not
defined
            at namespace scope.

    gcc/testsuite/ChangeLog:

            PR c++/97536
            * g++.dg/concepts/diagnostic16.C: New test.

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

* [Bug c++/97536] [concepts] parser segfault for concept defined in function template
  2020-10-23  1:14 [Bug c++/97536] New: [concepts] parser segfault for concept defined in function template hello at josephloser dot com
                   ` (2 preceding siblings ...)
  2021-04-19 22:06 ` cvs-commit at gcc dot gnu.org
@ 2021-04-19 22:07 ` mpolacek at gcc dot gnu.org
  2022-01-04  2:20 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-04-19 22:07 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed in GCC 11.

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

* [Bug c++/97536] [concepts] parser segfault for concept defined in function template
  2020-10-23  1:14 [Bug c++/97536] New: [concepts] parser segfault for concept defined in function template hello at josephloser dot com
                   ` (3 preceding siblings ...)
  2021-04-19 22:07 ` mpolacek at gcc dot gnu.org
@ 2022-01-04  2:20 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-04  2:20 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |11.0

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

end of thread, other threads:[~2022-01-04  2:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-23  1:14 [Bug c++/97536] New: [concepts] parser segfault for concept defined in function template hello at josephloser dot com
2020-10-26 16:49 ` [Bug c++/97536] " mpolacek at gcc dot gnu.org
2021-03-30 15:52 ` mpolacek at gcc dot gnu.org
2021-04-19 22:06 ` cvs-commit at gcc dot gnu.org
2021-04-19 22:07 ` mpolacek at gcc dot gnu.org
2022-01-04  2:20 ` 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).