Message ID | CAEwic4Zoeeyz6qo3ctCJ6AHDQ8r0mcgUN4SWaCBwdsZp+tJBLA@mail.gmail.com |
---|---|
State | New |
Headers | show |
How does this happen? Are we setting DECL_ATTRIBUTES twice? Jason
2012/1/17 Jason Merrill <jason@redhat.com>: > How does this happen? Are we setting DECL_ATTRIBUTES twice? > > Jason Yes, we call it for this example twice. One time in 'begin_class_definition'. and second time in 'do_friend'. Kai
On 01/17/2012 02:30 PM, Kai Tietz wrote: > 2012/1/17 Jason Merrill<jason@redhat.com>: >> How does this happen? Are we setting DECL_ATTRIBUTES twice? > > Yes, we call it for this example twice. One time in > 'begin_class_definition'. and second time in 'do_friend'. Surely the call from begin_class_definition isn't for the function declaration, though. Jason
2012/1/17 Jason Merrill <jason@redhat.com>: > On 01/17/2012 02:30 PM, Kai Tietz wrote: >> >> 2012/1/17 Jason Merrill<jason@redhat.com>: >>> >>> How does this happen? Are we setting DECL_ATTRIBUTES twice? >> >> >> Yes, we call it for this example twice. One time in >> 'begin_class_definition'. and second time in 'do_friend'. > > > Surely the call from begin_class_definition isn't for the function > declaration, though. > > Jason Right, but in second call we get for cplus_decl_attributes's late_attrs (as result of splice_template_attributes) the same value as already stored in decl_p's attributes. By this we chain up an endless-recusion. Kai
On 01/17/2012 02:41 PM, Kai Tietz wrote: > Right, but in second call we get for cplus_decl_attributes's > late_attrs (as result of splice_template_attributes) the same value as > already stored in decl_p's attributes. Right, but why is it already stored there? Jason
2012/1/17 Jason Merrill <jason@redhat.com>: > On 01/17/2012 02:41 PM, Kai Tietz wrote: >> >> Right, but in second call we get for cplus_decl_attributes's >> late_attrs (as result of splice_template_attributes) the same value as >> already stored in decl_p's attributes. > > > Right, but why is it already stored there? > > Jason The approach to disable cplus_decl_attributes call in do_friend (as we assume that prior grok* function it is calling it already) doesn't work. Eg the tests in g++.dg/ext/attribute-test-[34].C are failing for c++11. do_friend is called here via grokdeclarator for 'fTest' (test 3) and the attributes weren't applied before. So removing here in do_friend the call of cplus_decl_attributes seems wrong. With my orginal patch those tests are passing. Regards, Kai
Index: gcc/cp/decl2.c =================================================================== --- gcc/cp/decl2.c (revision 183106) +++ gcc/cp/decl2.c (working copy) @@ -1202,7 +1202,8 @@ /* Place the late attributes at the beginning of the attribute list. */ - TREE_CHAIN (tree_last (late_attrs)) = *q; + if (late_attrs != *q) + TREE_CHAIN (tree_last (late_attrs)) = *q; *q = late_attrs; if (!DECL_P (*decl_p) && *decl_p == TYPE_MAIN_VARIANT (*decl_p)) Index: gcc/gcc/testsuite/g++.dg/torture/pr51344.C =================================================================== --- /dev/null +++ gcc/gcc/testsuite/g++.dg/torture/pr51344.C @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +template <class T> +class B +{ + friend __attribute__((cdecl)) A& operator >>(A& a, B& b) + { + return a; + } +};