diff --git a/gcc/cp/cp-gimplify.cc b/gcc/cp/cp-gimplify.cc index 1216ef17b081d2ae61c1612336cb5378b7d9ca40..216a6231d6fcfb5f22fde455cd02d4c453008dbb 100644 --- a/gcc/cp/cp-gimplify.cc +++ b/gcc/cp/cp-gimplify.cc @@ -3267,6 +3267,16 @@ process_stmt_assume_attribute (tree std_attrs, tree statement, for (; attr; attr = lookup_attribute ("gnu", "assume", TREE_CHAIN (attr))) { tree args = TREE_VALUE (attr); + if (args && PACK_EXPANSION_P (args)) + { + auto_diagnostic_group d; + error_at (attrs_loc, "pack expansion of %qE attribute", + get_attribute_name (attr)); + if (cxx_dialect >= cxx17) + inform (attrs_loc, "use fold expression in the attribute " + "argument instead"); + continue; + } int nargs = list_length (args); if (nargs != 1) { diff --git a/gcc/testsuite/g++.dg/cpp23/attr-assume11.C b/gcc/testsuite/g++.dg/cpp23/attr-assume11.C new file mode 100644 index 0000000000000000000000000000000000000000..df6e5890d4ca6dc724e3d1a6f1352e04a09b1124 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp23/attr-assume11.C @@ -0,0 +1,22 @@ +// PR c++/109756 +// { dg-do compile { target c++11 } } + +template <int ...args> +void +foo () +{ + [[assume (1 > 0)...]]; // { dg-error "expansion pattern '\\\(1 > 0\\\)' contains no parameter packs" } + // { dg-warning "attributes at the beginning of statement are ignored" "" { target *-*-* } .-1 } + [[assume (args > 0)...]]; // { dg-error "pack expansion of 'assume' attribute" } + // { dg-message "use fold expression in the attribute argument instead" "" { target c++17 } .-1 } +#if __cpp_fold_expressions >= 201603L + [[assume (((args > 0) && ...))]]; +#endif + [[gnu::assume (1 > 0)...]]; // { dg-error "expansion pattern '\\\(1 > 0\\\)' contains no parameter packs" } + // { dg-warning "attributes at the beginning of statement are ignored" "" { target *-*-* } .-1 } + [[gnu::assume (args > 0)...]]; // { dg-error "pack expansion of 'assume' attribute" } + // { dg-message "use fold expression in the attribute argument instead" "" { target c++17 } .-1 } +#if __cpp_fold_expressions >= 201603L + [[gnu::assume (((args > 0) && ...))]]; +#endif +}