I've tried this with both older versions as well as GCC 12.3 (latest I have access to). This is on GNU/Linux on x86_64.
I have the following code: #include <exception> class Exception : public std::exception { public: Exception(const char* text, ...) __attribute__((format(printf, 2, 3))); }; void foo() { throw Exception("something bad"); } this works fine. However, due to some diamond inheritance I need to switch to virtual inheritance here: #include <exception> class Exception : public /**/ virtual /**/ std::exception { public: Exception(const char* text, ...) __attribute__((format(printf, 2, 3))); }; void foo() { throw Exception("something bad"); } this does not work AT ALL. First, the extra virtual infrastructure means that the offsets we use (note we need to add one to the format parameters anyway due to the this pointer I assume) are wrong: /tmp/virt.cpp:7:45: error: 'format' attribute argument 2 value '2' refers to parameter type 'int' 7 | __attribute__((format(printf, 2, 3))); | ^ Just adding 1 to this, for 3, 4, doesn't help: /tmp/virt.cpp:7:45: error: 'format' attribute argument 2 value '3' refers to parameter type 'const void**' 7 | __attribute__((format(printf, 3, 4))); | ^ And if I add 2 instead so it's 4,5 instead, I get an ICE: /tmp/virt.cpp: In function 'void foo()': /tmp/virt.cpp:12:36: error: 'format' attribute argument 2 value '4' exceeds the number of function parameters 2 [-Werror=attributes] 12 | throw Exception("something bad"); | ^ /tmp/virt.cpp:12:36: internal compiler error: in get_constant, at c-family/c-format.cc:323 0x7fba675a3082 __libc_start_main ../csu/libc-start.c:308 Please submit a full bug report, with preprocessed source (by using -freport-bug). Please include the complete backtrace with any bug report. See <https://gcc.gnu.org/bugs/> for instructions. I'm assuming a bug should be filed for this ICE (can anyone repro it in the current release?), but does anyone know if there's any way to make it work in GCC 12.3?