public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Alexandre Oliva <aoliva@redhat.com>
To: Jason Merrill <jason@redhat.com>
Cc: gcc-patches@gcc.gnu.org, nathan@acm.org
Subject: Re: [C++ PATCH] [PR87768] do not suppress location wrappers when tsubsting
Date: Thu, 17 Jan 2019 04:26:00 -0000	[thread overview]
Message-ID: <ora7jzgba7.fsf@lxoliva.fsfla.org> (raw)
In-Reply-To: <bd244a7b-9505-9b4d-f8bc-03d20edf36eb@redhat.com> (Jason	Merrill's message of "Wed, 2 Jan 2019 16:41:26 -0500")

On Jan  2, 2019, Jason Merrill <jason@redhat.com> wrote:

> On 12/30/18 11:31 PM, Alexandre Oliva wrote:
>> Concepts-checking and other kinds of early tsubsting may often take
>> place while location wrappers are suppressed, e.g. because we've
>> triggered template instantiation within template parameter lists.
>> 
>> With that, exprs that are usually wrapped by VIEW_CONVERT_EXPRs
>> location wrappers may end up wrapped by NON_LVALUE_EXPRs that are not
>> marked as location wrappers.  If such NON_LVALUE_EXPRs tsubsted exprs
>> undergo another round of tsubsting, say for constraint checking, or
>> even for another round of specialization, they will be rejected by
>> tsubst_copy_and_build.

>> This patch introduces a sentinel to reset suppress_location_wrappers
>> to zero, and uses it for template class and decl instantiation,
>> including constraint checking.

> Instead of a new class, let's add this to saved_scope and
> push_to/pop_from_top_level.

Like this?  Regstrapped on x86_64- and i686-linux-gnu.


[PR87768] reset location wrapper suppression when reentering top level

Concepts-checking and other kinds of early tsubsting may often take
place while location wrappers are suppressed, e.g. because we've
triggered template instantiation within template parameter lists.

With that, exprs that are usually wrapped by VIEW_CONVERT_EXPRs
location wrappers may end up wrapped by NON_LVALUE_EXPRs that are not
marked as location wrappers.  If such NON_LVALUE_EXPRs tsubsted exprs
undergo another round of tsubsting, say for constraint checking, or
even for another round of specialization, they will be rejected by
tsubst_copy_and_build.

This patch arranges for suppress_location_wrappers to be saved and
reset when pushing to the top level, and restored when popping from
it.


for  gcc/cp/ChangeLog

	PR c++/87768
	* cp-tree.h (saved_scope): Add suppress_location_wrappers.
	* name-lookup.c (do_push_to_top_level): Save and reset it.
	(do_pop_from_top_level): Restore it.

for  gcc/testsuite/ChangeLog

	PR c++/87768
	* g++.dg/concepts/pr87768.C: New.
---
 gcc/cp/cp-tree.h                        |    1 +
 gcc/cp/name-lookup.c                    |    3 +++
 gcc/testsuite/g++.dg/concepts/pr87768.C |   14 ++++++++++++++
 3 files changed, 18 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/concepts/pr87768.C

diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 6a2004330d23..c3a53b8292cf 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -1625,6 +1625,7 @@ struct GTY(()) saved_scope {
 
   int x_processing_template_decl;
   int x_processing_specialization;
+  int suppress_location_wrappers;
   BOOL_BITFIELD x_processing_explicit_instantiation : 1;
   BOOL_BITFIELD need_pop_function_context : 1;
 
diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
index b65fd5f463a1..d7b9029b0a3a 100644
--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -7133,6 +7133,7 @@ do_push_to_top_level (void)
   s->function_decl = current_function_decl;
   s->unevaluated_operand = cp_unevaluated_operand;
   s->inhibit_evaluation_warnings = c_inhibit_evaluation_warnings;
+  s->suppress_location_wrappers = suppress_location_wrappers;
   s->x_stmt_tree.stmts_are_full_exprs_p = true;
 
   scope_chain = s;
@@ -7143,6 +7144,7 @@ do_push_to_top_level (void)
   push_class_stack ();
   cp_unevaluated_operand = 0;
   c_inhibit_evaluation_warnings = 0;
+  suppress_location_wrappers = 0;
 }
 
 static void
@@ -7175,6 +7177,7 @@ do_pop_from_top_level (void)
   current_function_decl = s->function_decl;
   cp_unevaluated_operand = s->unevaluated_operand;
   c_inhibit_evaluation_warnings = s->inhibit_evaluation_warnings;
+  suppress_location_wrappers = s->suppress_location_wrappers;
 
   /* Make this saved_scope structure available for reuse by
      push_to_top_level.  */
diff --git a/gcc/testsuite/g++.dg/concepts/pr87768.C b/gcc/testsuite/g++.dg/concepts/pr87768.C
new file mode 100644
index 000000000000..de436e5d9edd
--- /dev/null
+++ b/gcc/testsuite/g++.dg/concepts/pr87768.C
@@ -0,0 +1,14 @@
+// { dg-do compile { target c++17 } }
+// { dg-options "-fconcepts" }
+
+struct a {};
+template <bool> using b = a;
+
+template <typename> struct c;
+template <typename d>
+  requires requires(d e) { e[0]; }
+struct c<d> {
+  static constexpr bool f = [] { return false; }();
+};
+
+struct g : b<c<unsigned[]>::f> {};


-- 
Alexandre Oliva, freedom fighter   https://FSFLA.org/blogs/lxo
Be the change, be Free!         FSF Latin America board member
GNU Toolchain Engineer                Free Software Evangelist
Hay que enGNUrecerse, pero sin perder la terGNUra jamás-GNUChe

  reply	other threads:[~2019-01-17  4:26 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-31 10:27 Alexandre Oliva
2019-01-02 21:41 ` Jason Merrill
2019-01-17  4:26   ` Alexandre Oliva [this message]
2019-01-17  4:34     ` Jason Merrill

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=ora7jzgba7.fsf@lxoliva.fsfla.org \
    --to=aoliva@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    --cc=nathan@acm.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).