public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/103901] New: A lambda with a new type in its body cannot be defined inside template parameter list
@ 2022-01-04  8:35 fchelnokov at gmail dot com
  2022-01-04 18:37 ` [Bug c++/103901] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: fchelnokov at gmail dot com @ 2022-01-04  8:35 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 103901
           Summary: A lambda with a new type in its body cannot be defined
                    inside template parameter list
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

The following valid struct template definition:
```
template <auto = []{ struct A{}; }>
struct B {};
```
is accepted by Clang and MSVC, but not by GCC that complains `error: definition
of 'struct<lambda()>::A' inside template parameter list`. Demo:
https://gcc.godbolt.org/z/f1dxGbPvs

Related discussion: https://stackoverflow.com/q/70571380/7325599

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

* [Bug c++/103901] A lambda with a new type in its body cannot be defined inside template parameter list
  2022-01-04  8:35 [Bug c++/103901] New: A lambda with a new type in its body cannot be defined inside template parameter list fchelnokov at gmail dot com
@ 2022-01-04 18:37 ` pinskia at gcc dot gnu.org
  2022-01-04 18:38 ` pinskia at gcc dot gnu.org
  2022-01-04 20:15 ` jakub at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-04 18:37 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2022-01-04
     Ever confirmed|0                           |1
             Blocks|                            |54367
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.
I thought I had saw a similar bug before.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54367
[Bug 54367] [meta-bug] lambda expressions

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

* [Bug c++/103901] A lambda with a new type in its body cannot be defined inside template parameter list
  2022-01-04  8:35 [Bug c++/103901] New: A lambda with a new type in its body cannot be defined inside template parameter list fchelnokov at gmail dot com
  2022-01-04 18:37 ` [Bug c++/103901] " pinskia at gcc dot gnu.org
@ 2022-01-04 18:38 ` pinskia at gcc dot gnu.org
  2022-01-04 20:15 ` jakub at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-04 18:38 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=101911

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #1)
> I thought I had saw a similar bug before.

I did PR 101911.

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

* [Bug c++/103901] A lambda with a new type in its body cannot be defined inside template parameter list
  2022-01-04  8:35 [Bug c++/103901] New: A lambda with a new type in its body cannot be defined inside template parameter list fchelnokov at gmail dot com
  2022-01-04 18:37 ` [Bug c++/103901] " pinskia at gcc dot gnu.org
  2022-01-04 18:38 ` pinskia at gcc dot gnu.org
@ 2022-01-04 20:15 ` jakub at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-01-04 20:15 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org,
                   |                            |jason at gcc dot gnu.org,
                   |                            |ppalka at gcc dot gnu.org

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
If it is valid, I think e.g.
--- gcc/cp/parser.c.jj  2022-01-04 09:59:37.297641779 +0100
+++ gcc/cp/parser.c     2022-01-04 20:56:19.065070397 +0100
@@ -11046,6 +11046,9 @@ cp_parser_lambda_expression (cp_parser*
     bool save_in_consteval_if_p = in_consteval_if_p;
     in_consteval_if_p = false;

+    int saved_processing_template_parmlist = processing_template_parmlist;
+    processing_template_parmlist = 0;
+
     /* By virtue of defining a local class, a lambda expression has access to
        the private variables of enclosing classes.  */

@@ -11078,6 +11081,7 @@ cp_parser_lambda_expression (cp_parser*

     in_consteval_if_p = save_in_consteval_if_p;
     in_discarded_stmt = discarded;
+    processing_template_parmlist = saved_processing_template_parmlist;

     parser->num_template_parameter_lists = saved_num_template_parameter_lists;
     parser->in_statement = in_statement;
should fix that.  But as the stack-overflow link says, it is unclear.
Also, we still reject even with the above patch
decltype ([]{ struct A {} ; return 1; }) a;
(guess that is PR101911).

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

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

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-04  8:35 [Bug c++/103901] New: A lambda with a new type in its body cannot be defined inside template parameter list fchelnokov at gmail dot com
2022-01-04 18:37 ` [Bug c++/103901] " pinskia at gcc dot gnu.org
2022-01-04 18:38 ` pinskia at gcc dot gnu.org
2022-01-04 20:15 ` jakub 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).