public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Paul Smith <psmith@gnu.org>
To: gcc@gcc.gnu.org
Subject: GCC 12.3 ICE: format(printf...) failing in C++ with virtual inheritance
Date: Fri, 08 Dec 2023 17:21:50 -0500	[thread overview]
Message-ID: <b3a1e8b8561c88872e58fc6fcf81397542919c74.camel@gnu.org> (raw)

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?

             reply	other threads:[~2023-12-08 22:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-08 22:21 Paul Smith [this message]
2023-12-09 10:03 ` Amol Surati

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b3a1e8b8561c88872e58fc6fcf81397542919c74.camel@gnu.org \
    --to=psmith@gnu.org \
    --cc=gcc@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).