to our attributes parameter. */
gcc_assert (*p == attributes);
}
+ else if (FUNC_OR_METHOD_TYPE_P (*decl_p))
+ p = NULL;
else
{
p = &TYPE_ATTRIBUTES (*decl_p);
tree nondep = t;
/* Apply any non-dependent attributes. */
- *p = nondep;
+ if (p)
+ *p = nondep;
+ else if (nondep)
+ *decl_p = cp_build_type_attribute_variant (*decl_p, nondep);
if (nondep == attributes)
return true;
identical to T. */
static tree
-rebuild_function_or_method_type (tree t, tree return_type, tree arg_types,
- tree raises, tsubst_flags_t complain)
+rebuild_function_or_method_type (tree t, tree args, tree return_type,
+ tree arg_types, tree raises,
+ tsubst_flags_t complain)
{
gcc_assert (FUNC_OR_METHOD_TYPE_P (t));
new_type = build_method_type_directly (r, return_type,
TREE_CHAIN (arg_types));
}
- new_type = cp_build_type_attribute_variant (new_type, TYPE_ATTRIBUTES (t));
+ if (!apply_late_template_attributes (&new_type, TYPE_ATTRIBUTES (t), 0,
+ args, complain, NULL_TREE))
+ return error_mark_node;
cp_ref_qualifier rqual = type_memfn_rqual (t);
bool late_return_type_p = TYPE_HAS_LATE_RETURN_TYPE (t);
resolution for Core issues 1001/1322. */
static void
-maybe_rebuild_function_decl_type (tree decl)
+maybe_rebuild_function_decl_type (tree decl, tree args)
{
bool function_type_needs_rebuilding = false;
if (tree parm_list = FUNCTION_FIRST_USER_PARM (decl))
*q = void_list_node;
TREE_TYPE (decl)
- = rebuild_function_or_method_type (fntype,
+ = rebuild_function_or_method_type (fntype, args,
TREE_TYPE (fntype), new_parm_type_list,
TYPE_RAISES_EXCEPTIONS (fntype), tf_none);
}
DECL_ARGUMENTS (r) = parms;
DECL_RESULT (r) = NULL_TREE;
- maybe_rebuild_function_decl_type (r);
+ maybe_rebuild_function_decl_type (r, args);
TREE_STATIC (r) = 0;
TREE_PUBLIC (r) = TREE_PUBLIC (t);
}
/* Construct a new type node and return it. */
- return rebuild_function_or_method_type (t, return_type, arg_types,
+ return rebuild_function_or_method_type (t, args, return_type, arg_types,
/*raises=*/NULL_TREE, complain);
}
--- /dev/null
+// PR c++/116175
+// { dg-do compile { target c++11 } }
+// { dg-options "-Wformat" }
+
+template <typename ...T>
+int foo (T ...args, const char *fmt, ...)
+[[gnu::format (printf, 1 + sizeof... (T), 2 + sizeof... (T))]];
+
+int a = foo <> ("%d", 1);
+int b = foo <int, int, int, int, int> (1, 2, 3, 4, 5, "%d", 1);
+int c = foo <> ("%f", 1); // { dg-warning "format '%f' expects argument of type 'double', but argument 2 has type 'int'" }
+int d = foo <int, int, int, int, int> (1, 2, 3, 4, 5, "%f", 1); // { dg-warning "format '%f' expects argument of type 'double', but argument 7 has type 'int'" }