Hi! cplus_decl_attributes can be called with attributes equal to error_mark_node, there are some spots in the function that test it or decl_attributes it calls starts with: if (TREE_TYPE (*node) == error_mark_node || attributes == error_mark_node) return NULL_TREE; But the recent PR104245 change broke this when processing_template_decl is true.
This fixes it and also fixes an OpenMP problem with such attributes. Ok for trunk if it passes bootstrap/regtest? 2022-03-25 Jakub Jelinek <ja...@redhat.com> PR c++/104668 * decl2.cc (splice_template_attributes): Return NULL if *p is error_mark_node. (cplus_decl_attributes): Don't chain on OpenMP attributes if attributes is error_mark_node. * g++.dg/cpp0x/pr104668.C: New test. --- gcc/cp/decl2.cc.jj 2022-03-09 09:09:55.415843331 +0100 +++ gcc/cp/decl2.cc 2022-03-25 17:17:27.769036749 +0100 @@ -1336,7 +1336,7 @@ splice_template_attributes (tree *attr_p tree late_attrs = NULL_TREE; tree *q = &late_attrs; - if (!p) + if (!p || *p == error_mark_node) return NULL_TREE; for (; *p; ) @@ -1644,6 +1644,8 @@ cplus_decl_attributes (tree *decl, tree && DECL_CLASS_SCOPE_P (*decl)) error ("%q+D static data member inside of declare target directive", *decl); + else if (attributes == error_mark_node) + ; else if (VAR_P (*decl) && (processing_template_decl || !cp_omp_mappable_type (TREE_TYPE (*decl)))) --- gcc/testsuite/g++.dg/cpp0x/pr104668.C.jj 2022-03-25 17:25:42.280068058 +0100 +++ gcc/testsuite/g++.dg/cpp0x/pr104668.C 2022-03-25 17:24:44.862881444 +0100 @@ -0,0 +1,13 @@ +// PR c++/104668 +// { dg-do compile { target c++11 } } +// { dg-excess-errors "" } + +template <class... Ts> +void sink(Ts...); +template <class... Ts> +void f(Ts...) { + sink([] { struct alignas:Ts) S {}; }...); } +} +int main() { + f(0); +} Jakub