https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116175
Bug ID: 116175
Summary: ICE with dependent format attribute
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: jakub at gcc dot gnu.org
Target Milestone: ---
// { 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'"
}
ICEs because we never actually instantiate the dependent attribute.
attr-format4.C:8:16: warning: ‘format’ attribute argument 2 value ‘(1 +
sizeof... (T))’ is not an integer constant [-Wattributes]
8 | int a = foo <> ("%d", 1);
| ~~~~~~~^~~~~~~~~
attr-format4.C:8:16: internal compiler error: in validate_constant, at
c-family/c-format.cc:323
0x2f8d8be internal_error(char const*, ...)
../../gcc/diagnostic-global-context.cc:491
0xf75faf fancy_abort(char const*, int, char const*)
../../gcc/diagnostic.cc:1755
0x841a88 validate_constant
../../gcc/c-family/c-format.cc:323
0x841a88 validate_constant
../../gcc/c-family/c-format.cc:311
0x12b6645 decode_format_attr
../../gcc/c-family/c-format.cc:376