On Jan  2, 2019, Jason Merrill <ja...@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 via email to