diff mbox

[C++] Mini bunch of mini clean-ups

Message ID 5159B89E.6030704@oracle.com
State New
Headers show

Commit Message

Paolo Carlini April 1, 2013, 4:41 p.m. UTC
Hi,

three items:
- Remove DECL_UNBOUND_CLASS_TEMPLATE_P, unused outside cp-tree.h.
- Use get_containing_scope in 4 places (obvious I guess)
- Use existing predicates in 2 places (likewise)

Tested x86_64-linux. Ok?

Thanks,
Paolo.

PS: In my opinion we should also rename DECL_FUNCTION_MEMBER_P to 
DECL_MEMBER_FUNCTION_P. Objections?

///////////////////////////
2013-04-01  Paolo Carlini  <paolo.carlini@oracle.com>

	* cp-tree.h (DECL_UNBOUND_CLASS_TEMPLATE_P): Remove.
	(DECL_FUNCTION_TEMPLATE_P): Adjust.

	* cxx-pretty-print.c (pp_cxx_nested_name_specifier,
	pp_cxx_qualified_id): Use get_containing_scope.
	* parser.c (cp_parser_class_head): Likewise.
	* pt.c (push_template_decl_real): Likewise.

	* decl2.c (import_export_decl): Use DECL_TEMPLOID_INSTANTIATION.
	* pt.c (unify): Use CP_INTEGRAL_TYPE_P.

Comments

Jason Merrill April 1, 2013, 4:50 p.m. UTC | #1
On 04/01/2013 12:41 PM, Paolo Carlini wrote:
> +#define DECL_FUNCTION_TEMPLATE_P(NODE)                          \
> +  (TREE_CODE (NODE) == TEMPLATE_DECL                            \
> +   && DECL_TEMPLATE_RESULT (NODE) != NULL_TREE			\

Do we need the NULL_TREE check?  That is, do we still build a template 
with no result?

> PS: In my opinion we should also rename DECL_FUNCTION_MEMBER_P to DECL_MEMBER_FUNCTION_P. Objections?

The current name makes it clearer (to me, anyway) that the macro assumes 
that we already know we're looking at a FUNCTION_DECL.

Jason
Paolo Carlini April 1, 2013, 4:55 p.m. UTC | #2
Hi,

On 04/01/2013 06:50 PM, Jason Merrill wrote:
> On 04/01/2013 12:41 PM, Paolo Carlini wrote:
>> +#define DECL_FUNCTION_TEMPLATE_P(NODE)                          \
>> +  (TREE_CODE (NODE) == TEMPLATE_DECL \
>> +   && DECL_TEMPLATE_RESULT (NODE) != NULL_TREE            \
> Do we need the NULL_TREE check?  That is, do we still build a template 
> with no result?
Honestly, I don't know, I followed DECL_TYPE_TEMPLATE_P, I can see what 
happens if I remove it...
>
>> PS: In my opinion we should also rename DECL_FUNCTION_MEMBER_P to 
>> DECL_MEMBER_FUNCTION_P. Objections?
>
> The current name makes it clearer (to me, anyway) that the macro 
> assumes that we already know we're looking at a FUNCTION_DECL.
Ok, the subtlety wasn't clean to me looking at the other predicates and 
the comment. Let's leave it alone for now.

Paolo.
Paolo Carlini April 1, 2013, 5:11 p.m. UTC | #3
Hi again

On 04/01/2013 06:55 PM, Paolo Carlini wrote:
> Hi,
>
> On 04/01/2013 06:50 PM, Jason Merrill wrote:
>> On 04/01/2013 12:41 PM, Paolo Carlini wrote:
>>> +#define DECL_FUNCTION_TEMPLATE_P(NODE)                          \
>>> +  (TREE_CODE (NODE) == TEMPLATE_DECL \
>>> +   && DECL_TEMPLATE_RESULT (NODE) != NULL_TREE            \
>> Do we need the NULL_TREE check?  That is, do we still build a 
>> template with no result?
> Honestly, I don't know, I followed DECL_TYPE_TEMPLATE_P, I can see 
> what happens if I remove it...
We have an ICE for g++.dg/template/qualttp17.C. Is this something we 
want to further investigate now or shall I just leave the check in?

Thanks,
Paolo.
Jason Merrill April 1, 2013, 5:25 p.m. UTC | #4
On 04/01/2013 01:11 PM, Paolo Carlini wrote:
> We have an ICE for g++.dg/template/qualttp17.C. Is this something we
> want to further investigate now or shall I just leave the check in?

Leave the check.  The patch is OK.

Jason
diff mbox

Patch

Index: cp-tree.h
===================================================================
--- cp-tree.h	(revision 197302)
+++ cp-tree.h	(working copy)
@@ -3730,14 +3730,10 @@  more_aggr_init_expr_args_p (const aggr_init_expr_a
 #define DECL_TEMPLATE_TEMPLATE_PARM_P(NODE) \
   (TREE_CODE (NODE) == TEMPLATE_DECL && DECL_TEMPLATE_PARM_P (NODE))
 
-/* Nonzero if NODE is a TEMPLATE_DECL representing an
-   UNBOUND_CLASS_TEMPLATE tree node.  */
-#define DECL_UNBOUND_CLASS_TEMPLATE_P(NODE) \
-  (TREE_CODE (NODE) == TEMPLATE_DECL && !DECL_TEMPLATE_RESULT (NODE))
-
-#define DECL_FUNCTION_TEMPLATE_P(NODE)  \
-  (TREE_CODE (NODE) == TEMPLATE_DECL \
-   && !DECL_UNBOUND_CLASS_TEMPLATE_P (NODE) \
+/* Nonzero for a DECL that represents a function template.  */
+#define DECL_FUNCTION_TEMPLATE_P(NODE)                          \
+  (TREE_CODE (NODE) == TEMPLATE_DECL                            \
+   && DECL_TEMPLATE_RESULT (NODE) != NULL_TREE			\
    && TREE_CODE (DECL_TEMPLATE_RESULT (NODE)) == FUNCTION_DECL)
 
 /* Nonzero for a DECL that represents a class template or alias
Index: cxx-pretty-print.c
===================================================================
--- cxx-pretty-print.c	(revision 197302)
+++ cxx-pretty-print.c	(working copy)
@@ -260,7 +260,7 @@  pp_cxx_nested_name_specifier (cxx_pretty_printer *
 {
   if (!SCOPE_FILE_SCOPE_P (t) && t != pp->enclosing_scope)
     {
-      tree scope = TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t);
+      tree scope = get_containing_scope (t);
       pp_cxx_nested_name_specifier (pp, scope);
       pp_cxx_template_keyword_if_needed (pp, scope, t);
       pp_cxx_unqualified_id (pp, t);
@@ -308,7 +308,7 @@  pp_cxx_qualified_id (cxx_pretty_printer *pp, tree
 
     default:
       {
-	tree scope = TYPE_P (t) ? TYPE_CONTEXT (t) : DECL_CONTEXT (t);
+	tree scope = get_containing_scope (t);
 	if (scope != pp->enclosing_scope)
 	  {
 	    pp_cxx_nested_name_specifier (pp, scope);
Index: decl2.c
===================================================================
--- decl2.c	(revision 197302)
+++ decl2.c	(working copy)
@@ -2572,8 +2572,7 @@  import_export_decl (tree decl)
       else
 	comdat_p = true;
     }
-  else if (DECL_TEMPLATE_INSTANTIATION (decl)
-	   || DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (decl))
+  else if (DECL_TEMPLOID_INSTANTIATION (decl))
     {
       /* DECL is an implicit instantiation of a function or static
 	 data member.  */
Index: parser.c
===================================================================
--- parser.c	(revision 197302)
+++ parser.c	(working copy)
@@ -18773,9 +18773,7 @@  cp_parser_class_head (cp_parser* parser,
 
 	  for (scope = TREE_TYPE (type);
 	       scope && TREE_CODE (scope) != NAMESPACE_DECL;
-	       scope = (TYPE_P (scope)
-			? TYPE_CONTEXT (scope)
-			: DECL_CONTEXT (scope)))
+	       scope = get_containing_scope (scope))
 	    if (TYPE_P (scope)
 		&& CLASS_TYPE_P (scope)
 		&& CLASSTYPE_TEMPLATE_INFO (scope)
Index: pt.c
===================================================================
--- pt.c	(revision 197302)
+++ pt.c	(working copy)
@@ -4803,9 +4803,7 @@  push_template_decl_real (tree decl, bool is_friend
 	      /* Can happen in erroneous input.  */
 	      break;
 	    else
-	      current = (TYPE_P (current)
-			 ? TYPE_CONTEXT (current)
-			 : DECL_CONTEXT (current));
+	      current = get_containing_scope (current);
 	  }
 
       /* Check that the parms are used in the appropriate qualifying scopes
@@ -16750,8 +16748,7 @@  unify (tree tparms, tree targs, tree parm, tree ar
       else if (same_type_p (TREE_TYPE (arg), tparm))
 	/* OK */;
       else if ((strict & UNIFY_ALLOW_INTEGER)
-	       && (TREE_CODE (tparm) == INTEGER_TYPE
-		   || TREE_CODE (tparm) == BOOLEAN_TYPE))
+	       && CP_INTEGRAL_TYPE_P (tparm))
 	/* Convert the ARG to the type of PARM; the deduced non-type
 	   template argument must exactly match the types of the
 	   corresponding parameter.  */