http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52952
--- Comment #13 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-05-25 14:17:41 UTC --- I guess the C/C++ FEs could for non-trivial string literals put into a hash table mapping from locus_t (of ADDR_EXPR around STRING_CST) to the first cpp token for that string, then the diagnostic code could go from there. Trivial string literal above would be a string literal that doesn't have any prefixes (L/u/u8/U and variants with R), isn't contatenated from several parts and didn't need to be translated. So, printf ("%.*d"); (the common case) wouldn't have to be recorded, while printf (R"<<<(%)>>>" "." R"(*)" "d"); would need that. For "trivial" string literals you'd just shift the locus by the offset, for non-trivial look up the tokens and process them again, looking at where the corresponding byte would appear to come from.