diff mbox series

[PR,c+,94827] : template parm with default requires

Message ID 863ac97a-8780-89da-03b2-82b060b00cb5@acm.org
State New
Headers show
Series [PR,c+,94827] : template parm with default requires | expand

Commit Message

Nathan Sidwell April 29, 2020, 6:50 p.m. UTC
Jason,
this is the patch you suggested, as I understood it.  I kept 
finish_nested_require's saving of the (converted) 
current_template_parms, becase of the comment about use in diagnostics.

Is this what you meant?

boostrapped on x86_64-linux.

nathan

Comments

Nathan Sidwell April 30, 2020, 1:51 p.m. UTC | #1
On 4/29/20 2:50 PM, Nathan Sidwell wrote:
> Jason,
> this is the patch you suggested, as I understood it.  I kept 
> finish_nested_require's saving of the (converted) 
> current_template_parms, becase of the comment about use in diagnostics.
> 

this extended test that tries to call the function ices with the patch. 
So not there yet.

nathan
Jason Merrill April 30, 2020, 2:18 p.m. UTC | #2
On 4/29/20 2:50 PM, Nathan Sidwell wrote:
> Jason,
> this is the patch you suggested, as I understood it.  I kept 
> finish_nested_require's saving of the (converted) 
> current_template_parms, becase of the comment about use in diagnostics.
> 
> Is this what you meant?

Yes, this looks fine.

But I don't think that we need to keep saving the converted 
current_template_parms; diagnostics could also normalize using NULL_TREE 
args.  And it looks like diagnose_nested_requirement isn't currently 
doing re-normalization anyway.  This doesn't need to block the release, 
though.

Jason
Nathan Sidwell April 30, 2020, 2:35 p.m. UTC | #3
On 4/30/20 10:18 AM, Jason Merrill wrote:
> On 4/29/20 2:50 PM, Nathan Sidwell wrote:
>> Jason,
>> this is the patch you suggested, as I understood it.  I kept 
>> finish_nested_require's saving of the (converted) 
>> current_template_parms, becase of the comment about use in diagnostics.
>>
>> Is this what you meant?
> 
> Yes, this looks fine.
> 
> But I don't think that we need to keep saving the converted 
> current_template_parms; diagnostics could also normalize using NULL_TREE 
> args.  And it looks like diagnose_nested_requirement isn't currently 
> doing re-normalization anyway.  This doesn't need to block the release, 
> though.

Ok, I'll deal with that post-release.

Here's a modified version.  The only change is to remove an assert in 
tsubst_nested_requirement.  We have an arg_vec of 2, but only the first 
is filled in.  Thus we think the NULL one is a dependent type.

The testcase checks we evaluate the default arg as expected.

I don't expect the bootstrap to fail, because this is removing an assert.

nathan
Nathan Sidwell April 30, 2020, 3:29 p.m. UTC | #4
On 4/30/20 10:35 AM, Nathan Sidwell wrote:
> On 4/30/20 10:18 AM, Jason Merrill wrote:
>> On 4/29/20 2:50 PM, Nathan Sidwell wrote:
>>> Jason,
>>> this is the patch you suggested, as I understood it.  I kept 
>>> finish_nested_require's saving of the (converted) 
>>> current_template_parms, becase of the comment about use in diagnostics.
>>>
>>> Is this what you meant?
>>
>> Yes, this looks fine.
>>
>> But I don't think that we need to keep saving the converted 
>> current_template_parms; diagnostics could also normalize using 
>> NULL_TREE args.  And it looks like diagnose_nested_requirement isn't 
>> currently doing re-normalization anyway.  This doesn't need to block 
>> the release, though.
> 
> Ok, I'll deal with that post-release.
> 
> Here's a modified version.  The only change is to remove an assert in 
> tsubst_nested_requirement.  We have an arg_vec of 2, but only the first 
> is filled in.  Thus we think the NULL one is a dependent type.
> 
> The testcase checks we evaluate the default arg as expected.
> 
> I don't expect the bootstrap to fail, because this is removing an assert.

indeed it didn't.  The patch is pushed to trunk

nathan
diff mbox series

Patch

2020-04-27  Jason Merrill  <jason@redhat.com>
	    Nathan Sidwell  <nathan@acm.org>

	PR c++/94827
	* constraint.cc (map_arguments): If ARGS is null, it's a
	self-mapping of parms.
	(finish_nested_requirement): Do not pass argified
	current_template_parms to normalization.

diff --git c/gcc/cp/constraint.cc w/gcc/cp/constraint.cc
index 06161b8c8c4..a6009dc0c47 100644
--- c/gcc/cp/constraint.cc
+++ w/gcc/cp/constraint.cc
@@ -546,12 +546,16 @@  static tree
 map_arguments (tree parms, tree args)
 {
   for (tree p = parms; p; p = TREE_CHAIN (p))
-    {
-      int level;
-      int index;
-      template_parm_level_and_index (TREE_VALUE (p), &level, &index);
-      TREE_PURPOSE (p) = TMPL_ARG (args, level, index);
-    }
+    if (args)
+      {
+	int level;
+	int index;
+	template_parm_level_and_index (TREE_VALUE (p), &level, &index);
+	TREE_PURPOSE (p) = TMPL_ARG (args, level, index);
+      }
+    else
+      TREE_PURPOSE (p) = TREE_VALUE (p);
+
   return parms;
 }
 
@@ -2953,12 +2957,15 @@  finish_compound_requirement (location_t loc, tree expr, tree type, bool noexcept
 tree
 finish_nested_requirement (location_t loc, tree expr)
 {
+  /* Currently open template headers have dummy arg vectors, so don't
+     pass into normalization.  */
+  tree norm = normalize_constraint_expression (expr, NULL_TREE, false);
+  tree args = current_template_parms
+    ? template_parms_to_args (current_template_parms) : NULL_TREE;
+
   /* Save the normalized constraint and complete set of normalization
      arguments with the requirement.  We keep the complete set of arguments
      around for re-normalization during diagnostics.  */
-  tree args = current_template_parms
-    ? template_parms_to_args (current_template_parms) : NULL_TREE;
-  tree norm = normalize_constraint_expression (expr, args, false);
   tree info = build_tree_list (args, norm);
 
   /* Build the constraint, saving its normalization as its type.  */
diff --git c/gcc/testsuite/g++.dg/concepts/pr94827.C w/gcc/testsuite/g++.dg/concepts/pr94827.C
new file mode 100644
index 00000000000..a6c147bf303
--- /dev/null
+++ w/gcc/testsuite/g++.dg/concepts/pr94827.C
@@ -0,0 +1,7 @@ 
+// PR 94287 ICE looking inside open template-parm level
+// { dg-do compile { target c++17 } }
+// { dg-options -fconcepts }
+template <typename T,
+  bool = requires { requires (sizeof(T)==0); } >
+void foo(T) {}
+