This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH for c++/34913 (crash on vector attribute in template)
- From: Jason Merrill <jason at redhat dot com>
- To: gcc-patches List <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 24 Jan 2008 09:41:00 -0500
- Subject: C++ PATCH for c++/34913 (crash on vector attribute in template)
This patch fixes the bug by generalizing is_late_template_attribute to
defer all attributes with dependent arguments or modifying a dependent type.
Tested x86_64-pc-linux-gnu, applied to trunk.
2008-01-24 Jason Merrill <jason@redhat.com>
PR c++/34913
* decl2.c (is_late_template_attribute): Defer any attribute with
dependent args. Also defer type attributes if the type is dependent.
Index: cp/decl2.c
===================================================================
*** cp/decl2.c (revision 131755)
--- cp/decl2.c (working copy)
*************** is_late_template_attribute (tree attr, t
*** 985,1001 ****
tree name = TREE_PURPOSE (attr);
tree args = TREE_VALUE (attr);
const struct attribute_spec *spec = lookup_attribute_spec (name);
if (!spec)
/* Unknown attribute. */
return false;
! if (is_attribute_p ("aligned", name)
! && args
! && value_dependent_expression_p (TREE_VALUE (args)))
! /* Can't apply this until we know the desired alignment. */
! return true;
! else if (TREE_CODE (decl) == TYPE_DECL || spec->type_required)
{
tree type = TYPE_P (decl) ? decl : TREE_TYPE (decl);
--- 985,1009 ----
tree name = TREE_PURPOSE (attr);
tree args = TREE_VALUE (attr);
const struct attribute_spec *spec = lookup_attribute_spec (name);
+ tree arg;
if (!spec)
/* Unknown attribute. */
return false;
! /* If any of the arguments are dependent expressions, we can't evaluate
! the attribute until instantiation time. */
! for (arg = args; arg; arg = TREE_CHAIN (arg))
! {
! tree t = TREE_VALUE (arg);
! if (value_dependent_expression_p (t)
! || type_dependent_expression_p (t))
! return true;
! }
!
! if (TREE_CODE (decl) == TYPE_DECL
! || TYPE_P (decl)
! || spec->type_required)
{
tree type = TYPE_P (decl) ? decl : TREE_TYPE (decl);
*************** is_late_template_attribute (tree attr, t
*** 1006,1011 ****
--- 1014,1023 ----
|| code == BOUND_TEMPLATE_TEMPLATE_PARM
|| code == TYPENAME_TYPE)
return true;
+ /* Also defer attributes on dependent types. This is not necessary
+ in all cases, but is the better default. */
+ else if (dependent_type_p (type))
+ return true;
else
return false;
}
Index: testsuite/g++.dg/ext/vector11.C
===================================================================
*** testsuite/g++.dg/ext/vector11.C (revision 0)
--- testsuite/g++.dg/ext/vector11.C (revision 0)
***************
*** 0 ****
--- 1,6 ----
+ // PR c++/34913
+
+ template<typename T> struct A
+ {
+ int x[sizeof(T)] __attribute((vector_size(8)));
+ };