diff mbox

[c==] 71710 dependent FIELD_DECL

Message ID 32979419-a390-d0a5-85ca-353ae660e724@acm.org
State New
Headers show

Commit Message

Nathan Sidwell Jan. 23, 2017, 5:09 p.m. UTC
Jason,
Bug 71710 is a crash on 'decltype (a)', where 'a' is a FIELD_DECL wth 
dependent type.  finish_class_member_access_expr barfs on that.  The 
earlier sequence of if..elses has a check for FIELD_DECL, but that's in 
the shadow of a type_dependent_expression_p (object) check.  The field's 
type is the main template type, so it does have a type dependent object. 
  But there's no reason it shouldn't go through the usual 
finish_non_static_data_member processing.

Fixed by moving the FIELD_DECL check earlier.

ok?

nathan

Comments

Jason Merrill Jan. 23, 2017, 8:19 p.m. UTC | #1
On Mon, Jan 23, 2017 at 12:09 PM, Nathan Sidwell <nathan@acm.org> wrote:
> Jason,
> Bug 71710 is a crash on 'decltype (a)', where 'a' is a FIELD_DECL wth
> dependent type.  finish_class_member_access_expr barfs on that.  The earlier
> sequence of if..elses has a check for FIELD_DECL, but that's in the shadow
> of a type_dependent_expression_p (object) check.  The field's type is the
> main template type, so it does have a type dependent object.  But there's no
> reason it shouldn't go through the usual finish_non_static_data_member
> processing.

The issue is that we want to allow cases where the object type is the
current instantiation.

> Fixed by moving the FIELD_DECL check earlier.

...but this ought to handle that case fine, since the current
instantiation is when we will have successfully found a FIELD_DECL.

OK.

Jason
diff mbox

Patch

2017-01-23  Nathan Sidwell  <nathan@acm.org>

	PR c++/71710 - template using directive of field
	* pt.c (tsubst_copy_and_build [COMPONENT_REF]): Move FIELD_DECL
	check earlier.

	PR C++/71710
	* g++.dg/template/pr71710.C: New.

Index: cp/pt.c
===================================================================
--- cp/pt.c	(revision 244815)
+++ cp/pt.c	(working copy)
@@ -17470,7 +17470,14 @@  tsubst_copy_and_build (tree t,
 	if (member == error_mark_node)
 	  RETURN (error_mark_node);
 
-	if (type_dependent_expression_p (object))
+	if (TREE_CODE (member) == FIELD_DECL)
+	  {
+	    r = finish_non_static_data_member (member, object, NULL_TREE);
+	    if (TREE_CODE (r) == COMPONENT_REF)
+	      REF_PARENTHESIZED_P (r) = REF_PARENTHESIZED_P (t);
+	    RETURN (r);
+	  }
+	else if (type_dependent_expression_p (object))
 	  /* We can't do much here.  */;
 	else if (!CLASS_TYPE_P (object_type))
 	  {
@@ -17535,13 +17542,6 @@  tsubst_copy_and_build (tree t,
 	      }
 	    RETURN (error_mark_node);
 	  }
-	else if (TREE_CODE (member) == FIELD_DECL)
-	  {
-	    r = finish_non_static_data_member (member, object, NULL_TREE);
-	    if (TREE_CODE (r) == COMPONENT_REF)
-	      REF_PARENTHESIZED_P (r) = REF_PARENTHESIZED_P (t);
-	    RETURN (r);
-	  }
 
 	r = finish_class_member_access_expr (object, member,
 					     /*template_p=*/false,
Index: testsuite/g++.dg/template/pr71710.C
===================================================================
--- testsuite/g++.dg/template/pr71710.C	(revision 0)
+++ testsuite/g++.dg/template/pr71710.C	(working copy)
@@ -0,0 +1,10 @@ 
+// { dg-do compile { target c++11 } }
+// PR C++/71710 ICE with decltype & using
+
+template < typename > struct A
+{
+  A a;
+  template < int > using B = decltype (a);
+  B < 0 > b;
+  template < int C > B < C > foo ();
+};