public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/95388] New: C++20 & 17 Lambda capture of *this by Value causes ICE "in tsubst_decl at cp/pt.c"
@ 2020-05-28 15:19 eng.amehra at gmail dot com
  2020-06-26 12:06 ` [Bug c++/95388] [11 Regression] " rguenth at gcc dot gnu.org
  2020-10-16 11:49 ` rguenth at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: eng.amehra at gmail dot com @ 2020-05-28 15:19 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 95388
           Summary: C++20 & 17 Lambda capture of *this by Value causes ICE
                    "in tsubst_decl at cp/pt.c"
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: eng.amehra at gmail dot com
  Target Milestone: ---

1. While using lambda capture by value, cause ICE with gcc 11.0.0. I tried with
both  -std=c++17 & then with -std=c++20. Both give same error.

Short Error: internal compiler error: in tsubst_decl, at cp/pt.c:14637

What works:
1. On this online gcc comiler, it works for gcc10.1, but fails for trunk. Code
Code fails to compile on this link when compiler is set to gcc trunk -
https://godbolt.org/z/PNxfQc
Same code compiles on this link when compiler is set to gcc10.1 -
https://godbolt.org/z/izPfY_

2. It works fine with GCC 7.5.0 with compiler flag -std=c++17 on my machine.
(See machine details below)

My local machine details:
               Linux DESKTOP-SHA8RMO 4.4.0-18362-Microsoft #836-Microsoft
x86_64                                    x86_64 x86_64 GNU/Linux
               OS:
               "Ubuntu 18.04.4 LTS (Bionic Beaver)".

Code sample which causes error: 

#include <iostream>
#include <vector>
#include <algorithm>

class FeatureLambdaCaptureThis
{
private:
  int addend;

public:
  FeatureLambdaCaptureThis(int value) : addend{value}
  {
  }
  void DemoLambdaCapture_ThisByValue()
  {
    std::vector<int> values{1, 3, 5, 7, 9, 11, 13, 15};

    std::for_each(values.begin(), values.end(), [=, *this](auto &value) mutable
{
    value += addend;
        addend++;
     });
    std::cout << "\n" ;
    for (auto &value : values)
    {
      std::cout << " " << value;
    }
    std::cout << std::endl;
  }
};


int main(int argc, char *argv[])
{
  std::cout << "__cplusplus:" << __cplusplus << std::endl;
  FeatureLambdaCaptureThis obj{2};
  obj.DemoLambdaCapture_ThisByValue();
}

Detailed error log from my local machine:

51 |     std::for_each(values.begin(), values.end(), [=, *this](auto value) {
[build]       |                                                                
     ^
[build] 0x69059f tsubst_decl
[build]         ../../gcc/cp/pt.c:14637
[build] 0xa2c8eb tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
[build]         ../../gcc/cp/pt.c:17934
[build] 0xa2b96a tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
[build]         ../../gcc/cp/pt.c:17832
[build] 0xa29d14 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
[build]         ../../gcc/cp/pt.c:18151
[build] 0xa27c91 instantiate_decl(tree_node*, bool, bool)
[build]         ../../gcc/cp/pt.c:25622
[build] 0x95ce6a maybe_instantiate_decl
[build]         ../../gcc/cp/decl2.c:5377
[build] 0x95f520 maybe_instantiate_decl
[build]         ../../gcc/tree.h:3411
[build] 0x95f520 mark_used(tree_node*, int)
[build]         ../../gcc/cp/decl2.c:5573
[build] 0x8b3385 build_over_call
[build]         ../../gcc/cp/call.c:9082
[build] 0x8b8141 build_op_call_1
[build]         ../../gcc/cp/call.c:4889
[build] 0x8b8141 build_op_call(tree_node*, vec<tree_node*, va_gc, vl_embed>**,
int)
[build]         ../../gcc/cp/call.c:4918
[build] 0xa6f3ee finish_call_expr(tree_node*, vec<tree_node*, va_gc,
vl_embed>**, bool, bool, int)
[build]         ../../gcc/cp/semantics.c:2692
[build] 0xa39bdd tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*,
bool, bool)
[build]         ../../gcc/cp/pt.c:20017
[build] 0xa28439 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
[build]         ../../gcc/cp/pt.c:18750
[build] 0xa2a963 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
[build]         ../../gcc/cp/pt.c:17862
[build] 0xa2a3c3 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
[build]         ../../gcc/cp/pt.c:18061
[build] 0xa2b96a tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
[build]         ../../gcc/cp/pt.c:17832
[build] 0xa29d14 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool)
[build]         ../../gcc/cp/pt.c:18151
[build] 0xa27c91 instantiate_decl(tree_node*, bool, bool)
[build]         ../../gcc/cp/pt.c:25622
[build] 0x8dab1e instantiate_cx_fn_r
[build]         ../../gcc/cp/constexpr.c:6549
[build] Please submit a full bug report,
[build] with preprocessed source if appropriate.
[build] Please include the complete backtrace with any bug report.
[build] See <https://gcc.gnu.org/bugs/> for instructions.

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

* [Bug c++/95388] [11 Regression] C++20 & 17 Lambda capture of *this by Value causes ICE "in tsubst_decl at cp/pt.c"
  2020-05-28 15:19 [Bug c++/95388] New: C++20 & 17 Lambda capture of *this by Value causes ICE "in tsubst_decl at cp/pt.c" eng.amehra at gmail dot com
@ 2020-06-26 12:06 ` rguenth at gcc dot gnu.org
  2020-10-16 11:49 ` rguenth at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-06-26 12:06 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|                            |11.0
            Summary|[Regression 10/11]C++20 &   |[11 Regression] C++20 & 17
                   |17 Lambda capture of *this  |Lambda capture of *this by
                   |by Value causes ICE "in     |Value causes ICE "in
                   |tsubst_decl at cp/pt.c"     |tsubst_decl at cp/pt.c"
   Target Milestone|---                         |11.0
      Known to work|                            |10.1.0

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

* [Bug c++/95388] [11 Regression] C++20 & 17 Lambda capture of *this by Value causes ICE "in tsubst_decl at cp/pt.c"
  2020-05-28 15:19 [Bug c++/95388] New: C++20 & 17 Lambda capture of *this by Value causes ICE "in tsubst_decl at cp/pt.c" eng.amehra at gmail dot com
  2020-06-26 12:06 ` [Bug c++/95388] [11 Regression] " rguenth at gcc dot gnu.org
@ 2020-10-16 11:49 ` rguenth at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-10-16 11:49 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Meanwhile fixed.

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

end of thread, other threads:[~2020-10-16 11:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-28 15:19 [Bug c++/95388] New: C++20 & 17 Lambda capture of *this by Value causes ICE "in tsubst_decl at cp/pt.c" eng.amehra at gmail dot com
2020-06-26 12:06 ` [Bug c++/95388] [11 Regression] " rguenth at gcc dot gnu.org
2020-10-16 11:49 ` rguenth 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).