Not sure of the validity of the test, but clang accepts it and so do we, with this patch. We shouldn't attempt to dereference a pointer that could be NULL without checking it first.
Bootstrapped/regtested on x86_64-linux, ok for trunk? 2017-03-10 Marek Polacek <pola...@redhat.com> PR c++/79967 * decl.c (grokdeclarator): Check ATTRLIST before dereferencing it. * g++.dg/cpp0x/gen-attrs-63.C: New test. diff --git gcc/cp/decl.c gcc/cp/decl.c index 3e7316f..b51ef8a 100644 --- gcc/cp/decl.c +++ gcc/cp/decl.c @@ -11402,7 +11402,8 @@ grokdeclarator (const cp_declarator *declarator, if (declarator && declarator->kind == cdk_id - && declarator->std_attributes) + && declarator->std_attributes + && attrlist != NULL) /* [dcl.meaning]/1: The optional attribute-specifier-seq following a declarator-id appertains to the entity that is declared. */ *attrlist = chainon (*attrlist, declarator->std_attributes); diff --git gcc/testsuite/g++.dg/cpp0x/gen-attrs-63.C gcc/testsuite/g++.dg/cpp0x/gen-attrs-63.C index e69de29..05f53e3 100644 --- gcc/testsuite/g++.dg/cpp0x/gen-attrs-63.C +++ gcc/testsuite/g++.dg/cpp0x/gen-attrs-63.C @@ -0,0 +1,12 @@ +// PR c++/79967 +// { dg-do compile { target c++11 } } + +template <void f [[noreturn]]()> +struct A +{ + int g () { f (); return 0; } +}; + +void f (); + +void g (A<f> a) { a.g (); } Marek