Hello, this hang is caused by an end-less loop in private_lookup_attribute caused by double-chaining of attributes in decl2.c's save_template_attributes function. In save_template_attributes we need to check that attribute-list isn't equal to late_attrs before chaining them.
ChangeLog gcc/cp 2012-01-17 Kai Tietz <kti...@redhat.com> PR c++/51344 * decl2.c (save_template_attributes): Don't chain late-attributes with attribute-list, if they are same. ChangeLog gcc/cp 2012-01-17 Kai Tietz <kti...@redhat.com> g++.dg/torture/pr51344.C: New test. Bootstrapped and regression tested for x86_64-unknown-linux-gnu, x86_64-w64-mingw32, and i686-w64-mingw32. Ok for apply? 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; + } +};