public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ PATCH] [PR87768] do not suppress location wrappers when tsubsting
@ 2018-12-31 10:27 Alexandre Oliva
  2019-01-02 21:41 ` Jason Merrill
  0 siblings, 1 reply; 4+ messages in thread
From: Alexandre Oliva @ 2018-12-31 10:27 UTC (permalink / raw)
  To: gcc-patches; +Cc: jason, nathan

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.

Regstrapped on x86_64- and i686-linux-gnu.  Ok to install?


for  gcc/ChangeLog

	PR c++/87768
	* tree.h (auto_restore_location_wrappers): New sentinel class.

for  gcc/cp/ChangeLog

	PR c++/87768
	* pt.c (instantiate_class_template_1, instantiate_decl): Do
	not suppress location wrappers.

for  gcc/testsuite/ChangeLog

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

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 18b093e7d2d2..e4d07c5103b6 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -10895,6 +10895,10 @@ instantiate_class_template_1 (tree type)
      it now.  */
   deferring_access_check_sentinel acs (dk_no_deferred);
 
+  /* Do not drop location wrappers just because we're tsubsting e.g.
+     constraints while parsing e.g. template parameters.  */
+  auto_restore_location_wrappers sentinel;
+
   /* Determine what specialization of the original template to
      instantiate.  */
   t = most_specialized_partial_spec (type, tf_warning_or_error);
@@ -24172,6 +24176,10 @@ instantiate_decl (tree d, bool defer_ok, bool expl_inst_class_mem_p)
 
   timevar_push (TV_TEMPLATE_INST);
 
+  /* Do not drop location wrappers just because we're tsubsting e.g.
+     constraints while parsing e.g. template parameters.  */
+  auto_restore_location_wrappers sentinel;
+
   /* Set TD to the template whose DECL_TEMPLATE_RESULT is the pattern
      for the instantiation.  */
   td = template_for_substitution (d);
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> {};
diff --git a/gcc/tree.h b/gcc/tree.h
index ed37e5455743..5bab3b284074 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -1194,6 +1194,23 @@ class auto_suppress_location_wrappers
   ~auto_suppress_location_wrappers () { --suppress_location_wrappers; }
 };
 
+/* A class for restoring the creation of location wrappers.  */
+
+class auto_restore_location_wrappers
+{
+  const int saved;
+public:
+  auto_restore_location_wrappers ()
+    : saved (suppress_location_wrappers)
+  {
+    suppress_location_wrappers = 0;
+  }
+  ~auto_restore_location_wrappers ()
+  {
+    suppress_location_wrappers = saved;
+  }
+};
+
 /* In a TARGET_EXPR node.  */
 #define TARGET_EXPR_SLOT(NODE) TREE_OPERAND_CHECK_CODE (NODE, TARGET_EXPR, 0)
 #define TARGET_EXPR_INITIAL(NODE) TREE_OPERAND_CHECK_CODE (NODE, TARGET_EXPR, 1)

-- 
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

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

* Re: [C++ PATCH] [PR87768] do not suppress location wrappers when tsubsting
  2018-12-31 10:27 [C++ PATCH] [PR87768] do not suppress location wrappers when tsubsting Alexandre Oliva
@ 2019-01-02 21:41 ` Jason Merrill
  2019-01-17  4:26   ` Alexandre Oliva
  0 siblings, 1 reply; 4+ messages in thread
From: Jason Merrill @ 2019-01-02 21:41 UTC (permalink / raw)
  To: Alexandre Oliva, gcc-patches; +Cc: nathan

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.

Jason

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

* Re: [C++ PATCH] [PR87768] do not suppress location wrappers when tsubsting
  2019-01-02 21:41 ` Jason Merrill
@ 2019-01-17  4:26   ` Alexandre Oliva
  2019-01-17  4:34     ` Jason Merrill
  0 siblings, 1 reply; 4+ messages in thread
From: Alexandre Oliva @ 2019-01-17  4:26 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches, nathan

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

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

* Re: [C++ PATCH] [PR87768] do not suppress location wrappers when tsubsting
  2019-01-17  4:26   ` Alexandre Oliva
@ 2019-01-17  4:34     ` Jason Merrill
  0 siblings, 0 replies; 4+ messages in thread
From: Jason Merrill @ 2019-01-17  4:34 UTC (permalink / raw)
  To: Alexandre Oliva; +Cc: gcc-patches, nathan

On 1/16/19 11:26 PM, Alexandre Oliva wrote:
> 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.

OK.

Jason

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

end of thread, other threads:[~2019-01-17  4:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-31 10:27 [C++ PATCH] [PR87768] do not suppress location wrappers when tsubsting Alexandre Oliva
2019-01-02 21:41 ` Jason Merrill
2019-01-17  4:26   ` Alexandre Oliva
2019-01-17  4:34     ` Jason Merrill

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).