public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PR c++/53540 - using fails to be equivalent to typedef
@ 2012-08-16 22:15 Dodji Seketeli
  2012-10-08 14:24 ` PING " Dodji Seketeli
  2012-10-08 18:42 ` Jason Merrill
  0 siblings, 2 replies; 5+ messages in thread
From: Dodji Seketeli @ 2012-08-16 22:15 UTC (permalink / raw)
  To: Jason Merrill; +Cc: GCC Patches

Hello,

In the example of this problem report, during the substituting of int
into 'function', tsubst_aggr_type fails for the alias ctxt1.  This is
because TYPE_TEMPLATE_INFO looks for the TEMPLATE_INFO of the ctxt1
alias at the wrong place and was wrongly finding it to be NULL.
Namely, it was looking for it in the DECL_TEMPLATE_INFO of the
declaration of the type -- as if ctxt1 was an alias template
specialization -- rather than looking of it in its
CLASSTYPE_TEMPLATE_INFO.

Fixed thus.  The second hunk of the patch is just to prevent the
compiler from crashing when primary_template_instantiation_p is passed
an alias of a class template instantiation.

Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk.

gcc/cp

	* cp-tree.h (TYPE_TEMPLATE_INFO): For an alias that is not an
	instance of alias template, don't look for its TEMPLATE_INFO in
	its declaration.
	* pt.c (primary_template_instantiation_p): Don't crash on an alias
	that is not an instance of a template.

gcc/testsuite/

	* g++.dg/cpp0x/alias-decl-21.C: New test.
---
 gcc/cp/cp-tree.h                           |    4 ++--
 gcc/cp/pt.c                                |    1 +
 gcc/testsuite/g++.dg/cpp0x/alias-decl-21.C |   24 ++++++++++++++++++++++++
 3 files changed, 27 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/alias-decl-21.C

diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 44f3ac1..64a8830 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -2634,8 +2634,8 @@ extern void decl_shadowed_for_var_insert (tree, tree);
    template info for the alias template, not the one (if any) for the
    template of the underlying type.  */
 #define TYPE_TEMPLATE_INFO(NODE)					\
-  (TYPE_ALIAS_P (NODE)							\
-   ? ((TYPE_NAME (NODE) && DECL_LANG_SPECIFIC (TYPE_NAME (NODE)))	\
+  ((TYPE_ALIAS_P (NODE) && DECL_LANG_SPECIFIC (TYPE_NAME (NODE)))	\
+   ? (DECL_LANG_SPECIFIC (TYPE_NAME (NODE))				\
       ? DECL_TEMPLATE_INFO (TYPE_NAME (NODE))				\
       : NULL_TREE)							\
    : ((TREE_CODE (NODE) == ENUMERAL_TYPE)				\
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index ad81bab..3163bd4 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -2854,6 +2854,7 @@ primary_template_instantiation_p (const_tree t)
   else if (TYPE_P (t)
 	   && TYPE_TEMPLATE_INFO (t)
 	   && PRIMARY_TEMPLATE_P (TYPE_TI_TEMPLATE (t))
+	   && DECL_LANG_SPECIFIC (TYPE_NAME (t))
 	   && DECL_TEMPLATE_INSTANTIATION (TYPE_NAME (t)))
     return true;
   return false;
diff --git a/gcc/testsuite/g++.dg/cpp0x/alias-decl-21.C b/gcc/testsuite/g++.dg/cpp0x/alias-decl-21.C
new file mode 100644
index 0000000..b68fa93
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/alias-decl-21.C
@@ -0,0 +1,24 @@
+// Origin: PR c++/53540
+// { dg-do compile { target c++11 } }
+
+template <typename T>
+struct context
+{
+  typedef int type;
+};
+
+template <typename T>
+void function()
+{
+  using ctx1 = context<T>;
+  typename ctx1::type f1;
+
+  typedef context<T> ctx2;
+  typename ctx2::type f2;
+}
+
+int main()
+{
+  function<int>();
+}
+
-- 
		Dodji

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

* PING Re: [PATCH] PR c++/53540 - using fails to be equivalent to typedef
  2012-08-16 22:15 [PATCH] PR c++/53540 - using fails to be equivalent to typedef Dodji Seketeli
@ 2012-10-08 14:24 ` Dodji Seketeli
  2012-10-08 18:42 ` Jason Merrill
  1 sibling, 0 replies; 5+ messages in thread
From: Dodji Seketeli @ 2012-10-08 14:24 UTC (permalink / raw)
  To: Jason Merrill; +Cc: GCC Patches

Friendly pinging this patch.

Dodji Seketeli <dodji@redhat.com> writes:

> Hello,
>
> In the example of this problem report, during the substituting of int
> into 'function', tsubst_aggr_type fails for the alias ctxt1.  This is
> because TYPE_TEMPLATE_INFO looks for the TEMPLATE_INFO of the ctxt1
> alias at the wrong place and was wrongly finding it to be NULL.
> Namely, it was looking for it in the DECL_TEMPLATE_INFO of the
> declaration of the type -- as if ctxt1 was an alias template
> specialization -- rather than looking of it in its
> CLASSTYPE_TEMPLATE_INFO.
>
> Fixed thus.  The second hunk of the patch is just to prevent the
> compiler from crashing when primary_template_instantiation_p is passed
> an alias of a class template instantiation.
>
> Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk.
>
> gcc/cp
>
> 	* cp-tree.h (TYPE_TEMPLATE_INFO): For an alias that is not an
> 	instance of alias template, don't look for its TEMPLATE_INFO in
> 	its declaration.
> 	* pt.c (primary_template_instantiation_p): Don't crash on an alias
> 	that is not an instance of a template.
>
> gcc/testsuite/
>
> 	* g++.dg/cpp0x/alias-decl-21.C: New test.
> ---
>  gcc/cp/cp-tree.h                           |    4 ++--
>  gcc/cp/pt.c                                |    1 +
>  gcc/testsuite/g++.dg/cpp0x/alias-decl-21.C |   24 ++++++++++++++++++++++++
>  3 files changed, 27 insertions(+), 2 deletions(-)
>  create mode 100644 gcc/testsuite/g++.dg/cpp0x/alias-decl-21.C
>
> diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
> index 44f3ac1..64a8830 100644
> --- a/gcc/cp/cp-tree.h
> +++ b/gcc/cp/cp-tree.h
> @@ -2634,8 +2634,8 @@ extern void decl_shadowed_for_var_insert (tree, tree);
>     template info for the alias template, not the one (if any) for the
>     template of the underlying type.  */
>  #define TYPE_TEMPLATE_INFO(NODE)					\
> -  (TYPE_ALIAS_P (NODE)							\
> -   ? ((TYPE_NAME (NODE) && DECL_LANG_SPECIFIC (TYPE_NAME (NODE)))	\
> +  ((TYPE_ALIAS_P (NODE) && DECL_LANG_SPECIFIC (TYPE_NAME (NODE)))	\
> +   ? (DECL_LANG_SPECIFIC (TYPE_NAME (NODE))				\
>        ? DECL_TEMPLATE_INFO (TYPE_NAME (NODE))				\
>        : NULL_TREE)							\
>     : ((TREE_CODE (NODE) == ENUMERAL_TYPE)				\
> diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
> index ad81bab..3163bd4 100644
> --- a/gcc/cp/pt.c
> +++ b/gcc/cp/pt.c
> @@ -2854,6 +2854,7 @@ primary_template_instantiation_p (const_tree t)
>    else if (TYPE_P (t)
>  	   && TYPE_TEMPLATE_INFO (t)
>  	   && PRIMARY_TEMPLATE_P (TYPE_TI_TEMPLATE (t))
> +	   && DECL_LANG_SPECIFIC (TYPE_NAME (t))
>  	   && DECL_TEMPLATE_INSTANTIATION (TYPE_NAME (t)))
>      return true;
>    return false;
> diff --git a/gcc/testsuite/g++.dg/cpp0x/alias-decl-21.C b/gcc/testsuite/g++.dg/cpp0x/alias-decl-21.C
> new file mode 100644
> index 0000000..b68fa93
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp0x/alias-decl-21.C
> @@ -0,0 +1,24 @@
> +// Origin: PR c++/53540
> +// { dg-do compile { target c++11 } }
> +
> +template <typename T>
> +struct context
> +{
> +  typedef int type;
> +};
> +
> +template <typename T>
> +void function()
> +{
> +  using ctx1 = context<T>;
> +  typename ctx1::type f1;
> +
> +  typedef context<T> ctx2;
> +  typename ctx2::type f2;
> +}
> +
> +int main()
> +{
> +  function<int>();
> +}
> +

-- 
		Dodji

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

* Re: [PATCH] PR c++/53540 - using fails to be equivalent to typedef
  2012-08-16 22:15 [PATCH] PR c++/53540 - using fails to be equivalent to typedef Dodji Seketeli
  2012-10-08 14:24 ` PING " Dodji Seketeli
@ 2012-10-08 18:42 ` Jason Merrill
  2012-10-09 15:26   ` Dodji Seketeli
  1 sibling, 1 reply; 5+ messages in thread
From: Jason Merrill @ 2012-10-08 18:42 UTC (permalink / raw)
  To: Dodji Seketeli; +Cc: GCC Patches

Let's move the alias template case from primary_template_instantiation_p 
into alias_template_specialization_p and call the latter from the 
former.  And also call it from tsubst.

Jason

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

* Re: [PATCH] PR c++/53540 - using fails to be equivalent to typedef
  2012-10-08 18:42 ` Jason Merrill
@ 2012-10-09 15:26   ` Dodji Seketeli
  2012-10-09 15:47     ` Jason Merrill
  0 siblings, 1 reply; 5+ messages in thread
From: Dodji Seketeli @ 2012-10-09 15:26 UTC (permalink / raw)
  To: Jason Merrill; +Cc: GCC Patches

Jason Merrill <jason@redhat.com> writes:

> Let's move the alias template case from
> primary_template_instantiation_p into alias_template_specialization_p
> and call the latter from the former.  And also call it from tsubst.

Like the below?

Note that I have changed the type of the argument of
alias_template_specialization_p to const_tree to comply with the
constness of the argument of primary_template_instantiation_p.

Tested on x86_64-unknown-linux-gnu against trunk.

gcc/cp

	* cp-tree.h (TYPE_TEMPLATE_INFO): For an alias that is not an
	instance of alias template, don't look for its TEMPLATE_INFO in
	its declaration.
	(alias_template_specialization_p): Take const_tree.
	* pt.c (alias_template_specialization_p): Take a const_tree.
	Don't call primary_template_instantiation_p.
	(primary_template_instantiation_p): Call
	alias_template_specialization_p.

gcc/testsuite/

	* g++.dg/cpp0x/alias-decl-24.C: New test.
---
 gcc/cp/cp-tree.h                           |  6 +++---
 gcc/cp/pt.c                                | 17 +++++++----------
 gcc/testsuite/g++.dg/cpp0x/alias-decl-24.C | 24 ++++++++++++++++++++++++
 3 files changed, 34 insertions(+), 13 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/alias-decl-24.C

diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 370f072..35819ed 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -2646,8 +2646,8 @@ extern void decl_shadowed_for_var_insert (tree, tree);
    template info for the alias template, not the one (if any) for the
    template of the underlying type.  */
 #define TYPE_TEMPLATE_INFO(NODE)					\
-  (TYPE_ALIAS_P (NODE)							\
-   ? ((TYPE_NAME (NODE) && DECL_LANG_SPECIFIC (TYPE_NAME (NODE)))	\
+  ((TYPE_ALIAS_P (NODE) && DECL_LANG_SPECIFIC (TYPE_NAME (NODE)))	\
+   ? (DECL_LANG_SPECIFIC (TYPE_NAME (NODE))				\
       ? DECL_TEMPLATE_INFO (TYPE_NAME (NODE))				\
       : NULL_TREE)							\
    : ((TREE_CODE (NODE) == ENUMERAL_TYPE)				\
@@ -5437,7 +5437,7 @@ extern bool reregister_specialization		(tree, tree, tree);
 extern tree fold_non_dependent_expr		(tree);
 extern tree fold_non_dependent_expr_sfinae	(tree, tsubst_flags_t);
 extern bool alias_type_or_template_p            (tree);
-extern bool alias_template_specialization_p     (tree);
+extern bool alias_template_specialization_p     (const_tree);
 extern bool explicit_class_specialization_p     (tree);
 extern int push_tinst_level                     (tree);
 extern void pop_tinst_level                     (void);
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 1377b3e..d81626c 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -2929,10 +2929,7 @@ primary_template_instantiation_p (const_tree t)
   else if (CLASS_TYPE_P (t) && !TYPE_DECL_ALIAS_P (TYPE_NAME (t)))
     return CLASSTYPE_TEMPLATE_INSTANTIATION (t)
 	   && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t));
-  else if (TYPE_P (t)
-	   && TYPE_TEMPLATE_INFO (t)
-	   && PRIMARY_TEMPLATE_P (TYPE_TI_TEMPLATE (t))
-	   && DECL_TEMPLATE_INSTANTIATION (TYPE_NAME (t)))
+  else if (alias_template_specialization_p (t))
     return true;
   return false;
 }
@@ -5077,11 +5074,14 @@ alias_type_or_template_p (tree t)
 /* Return TRUE iff is a specialization of an alias template.  */
 
 bool
-alias_template_specialization_p (tree t)
+alias_template_specialization_p (const_tree t)
 {
   if (t == NULL_TREE)
     return false;
-  return (primary_template_instantiation_p (t)
+  
+  return (TYPE_P (t)
+	  && TYPE_TEMPLATE_INFO (t)
+	  && PRIMARY_TEMPLATE_P (TYPE_TI_TEMPLATE (t))
 	  && DECL_ALIAS_TEMPLATE_P (TYPE_TI_TEMPLATE (t)));
 }
 
@@ -10945,10 +10945,7 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
     {
       tree decl = TYPE_NAME (t);
 
-      if (TYPE_DECL_ALIAS_P (decl)
-	  && DECL_LANG_SPECIFIC (decl)
-	  && DECL_TEMPLATE_INFO (decl)
-	  && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (decl)))
+      if (alias_template_specialization_p (t))
 	{
 	  /* DECL represents an alias template and we want to
 	     instantiate it.  */
diff --git a/gcc/testsuite/g++.dg/cpp0x/alias-decl-24.C b/gcc/testsuite/g++.dg/cpp0x/alias-decl-24.C
new file mode 100644
index 0000000..b68fa93
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/alias-decl-24.C
@@ -0,0 +1,24 @@
+// Origin: PR c++/53540
+// { dg-do compile { target c++11 } }
+
+template <typename T>
+struct context
+{
+  typedef int type;
+};
+
+template <typename T>
+void function()
+{
+  using ctx1 = context<T>;
+  typename ctx1::type f1;
+
+  typedef context<T> ctx2;
+  typename ctx2::type f2;
+}
+
+int main()
+{
+  function<int>();
+}
+
-- 
		Dodji

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

* Re: [PATCH] PR c++/53540 - using fails to be equivalent to typedef
  2012-10-09 15:26   ` Dodji Seketeli
@ 2012-10-09 15:47     ` Jason Merrill
  0 siblings, 0 replies; 5+ messages in thread
From: Jason Merrill @ 2012-10-09 15:47 UTC (permalink / raw)
  To: Dodji Seketeli; +Cc: GCC Patches

OK.

Jason

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

end of thread, other threads:[~2012-10-09 15:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-16 22:15 [PATCH] PR c++/53540 - using fails to be equivalent to typedef Dodji Seketeli
2012-10-08 14:24 ` PING " Dodji Seketeli
2012-10-08 18:42 ` Jason Merrill
2012-10-09 15:26   ` Dodji Seketeli
2012-10-09 15:47     ` 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).