public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: gcc-patches List <gcc-patches@gcc.gnu.org>
Subject: C++ PATCH for c++/48523 (lamda, 'this', templates)
Date: Mon, 11 Apr 2011 21:49:00 -0000	[thread overview]
Message-ID: <4DA37763.50008@redhat.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 224 bytes --]

Our rewriting for use of 'this' in a lambda used cp_build_indirect_ref, 
which assumes that we aren't in a template.  Using build_x_indirect_ref 
instead works better.

Tested x86_64-pc-linux-gnu, applying to trunk and 4.6.

[-- Attachment #2: 48523.patch --]
[-- Type: text/plain, Size: 1165 bytes --]

commit 9b7a53bda8938ff42074b1f38a3e0b68cb37e52e
Author: Jason Merrill <jason@redhat.com>
Date:   Sat Apr 9 01:40:20 2011 -0400

    	PR c++/48523
    	* tree.c (maybe_dummy_object): Use build_x_indirect_ref rather
    	than cp_build_indirect_ref.

diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index d6b6197..ad004bb 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -2423,7 +2423,7 @@ maybe_dummy_object (tree type, tree* binfop)
   else if (current != current_class_type
 	   && context == nonlambda_method_basetype ())
     /* In a lambda, need to go through 'this' capture.  */
-    decl = (cp_build_indirect_ref
+    decl = (build_x_indirect_ref
 	    ((lambda_expr_this_capture
 	      (CLASSTYPE_LAMBDA_EXPR (current_class_type))),
 	     RO_NULL, tf_warning_or_error));
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this4.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this4.C
new file mode 100644
index 0000000..29cd2a9
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this4.C
@@ -0,0 +1,13 @@
+// PR c++/48523
+// { dg-options -std=c++0x }
+
+template<typename>
+struct X
+{
+  bool b;
+
+  void f()
+  {
+    [this]{ return b; };
+  }
+};

                 reply	other threads:[~2011-04-11 21:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4DA37763.50008@redhat.com \
    --to=jason@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).