Another place we need to use fold_non_dependent_expr so that constant evaluation happens in non-template context.
Tested x86_64-pc-linux-gnu, applying to trunk.
commit 1f7ec60303854ae6c79034223aba5ad996b86843 Author: Jason Merrill <ja...@redhat.com> Date: Thu Apr 5 10:46:27 2018 -0400 PR c++/84665 - ICE with array of empty class. * decl2.c (cp_check_const_attributes): Use fold_non_dependent_expr. diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 6078fb668a7..b0bf8241f71 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -1416,7 +1416,7 @@ cp_check_const_attributes (tree attributes) { tree expr = TREE_VALUE (arg); if (EXPR_P (expr)) - TREE_VALUE (arg) = maybe_constant_value (expr); + TREE_VALUE (arg) = fold_non_dependent_expr (expr); } } } diff --git a/gcc/testsuite/g++.dg/ext/attr-noinline-4.C b/gcc/testsuite/g++.dg/ext/attr-noinline-4.C new file mode 100644 index 00000000000..27c7ae80fec --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/attr-noinline-4.C @@ -0,0 +1,10 @@ +// PR c++/84665 + +struct S {} a[1]; + +template <int N> +void +foo () +{ + __attribute__ ((noinline (a[0]))) int c = 0; // { dg-error "wrong number of arguments" } +}