C++ PATCH: PR 7363

Mark Mitchell mark@codesourcery.com
Tue Oct 29 13:13:00 GMT 2002


PR 7363 was a regression involving __alignof__ and templates; it was
fixed in the mainline in a superior, but far more invasive, way.  I've
checked in this version on the branch.

Tested on i686-pc-linux-gnu.

-- 
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

2002-10-29  Mark Mitchell  <mark@codesourcery.com>

	PR c++/7363
	* semantics.c (finish_alignof): Call complete_type before calling
	c_alignof.
	* decl2.c (build_expr_from_tree): Use
	finish_sizeof/finish_alignof.

2002-10-29  Mark Mitchell  <mark@codesourcery.com>

	* g++.dg/template/alignof1.C: New test.

Index: cp/decl2.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl2.c,v
retrieving revision 1.520.2.7.2.6
diff -c -p -r1.520.2.7.2.6 decl2.c
*** cp/decl2.c	8 Oct 2002 22:53:21 -0000	1.520.2.7.2.6
--- cp/decl2.c	29 Oct 2002 21:02:30 -0000
*************** build_expr_from_tree (t)
*** 3795,3804 ****
      case ALIGNOF_EXPR:
        {
  	tree r = build_expr_from_tree (TREE_OPERAND (t, 0));
! 	if (!TYPE_P (r))
! 	  return TREE_CODE (t) == SIZEOF_EXPR ? expr_sizeof (r) : c_alignof_expr (r);
! 	else
! 	  return TREE_CODE (t) == SIZEOF_EXPR ? c_sizeof (r) : c_alignof (r);
        }
  
      case MODOP_EXPR:
--- 3795,3802 ----
      case ALIGNOF_EXPR:
        {
  	tree r = build_expr_from_tree (TREE_OPERAND (t, 0));
! 	return (TREE_CODE (t) == SIZEOF_EXPR
! 		? finish_sizeof (r) : finish_alignof (r));
        }
  
      case MODOP_EXPR:
Index: cp/semantics.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/semantics.c,v
retrieving revision 1.252.2.6
diff -c -p -r1.252.2.6 semantics.c
*** cp/semantics.c	17 Apr 2002 01:44:01 -0000	1.252.2.6
--- cp/semantics.c	29 Oct 2002 21:02:31 -0000
*************** finish_alignof (t)
*** 2117,2123 ****
    if (processing_template_decl)
      return build_min_nt (ALIGNOF_EXPR, t);
  
!   return TYPE_P (t) ? c_alignof (t) : c_alignof_expr (t);
  }
  
  /* Generate RTL for the statement T, and its substatements, and any
--- 2117,2123 ----
    if (processing_template_decl)
      return build_min_nt (ALIGNOF_EXPR, t);
  
!   return TYPE_P (t) ? c_alignof (complete_type (t)) : c_alignof_expr (t);
  }
  
  /* Generate RTL for the statement T, and its substatements, and any
Index: testsuite/g++.dg/template/alignof1.C
===================================================================
RCS file: testsuite/g++.dg/template/alignof1.C
diff -N testsuite/g++.dg/template/alignof1.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/template/alignof1.C	29 Oct 2002 21:02:32 -0000
***************
*** 0 ****
--- 1,13 ----
+ template<typename T>
+ int my_alignof()
+ {
+     return __alignof__(T);
+ }
+ 
+ template<typename>
+ struct X { };
+ 
+ int main()
+ {
+   return my_alignof<X<void> >();
+ }



More information about the Gcc-patches mailing list