public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely.gcc@gmail.com>
To: Jonny Grant <jg@jguk.org>
Cc: gcc-help <gcc-help@gcc.gnu.org>
Subject: Re: __attribute__ error ("message")
Date: Fri, 31 Mar 2023 22:57:42 +0100	[thread overview]
Message-ID: <CAH6eHdRw48B_LnjLpgAfcct+yVwLyMGdCmgDdsKVtA4NsPXCSw@mail.gmail.com> (raw)
In-Reply-To: <6dc16e33-647e-5bf5-4025-3e10141aaa66@jguk.org>

On Fri, 31 Mar 2023 at 22:55, Jonny Grant wrote:
>
> Hello
>
> May I check, does this attribute error output the error message usually?
> My example links fine without any warnings or errors.
>
> Maybe I am misunderstanding it. I am sharing a simple program below and godbolt trunk example.
> I only get to see the error message if I don't implement the function and get a link failure.

Are you sure about that? If you remove the definition, you should get the error:

https://godbolt.org/z/z1hjn6Yan


>
> https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#Common-Function-Attributes
>
> error ("message")
> warning ("message")
>
> If the error or warning attribute is used on a function declaration and a call to such a function is not eliminated through dead code elimination or other optimizations, an error or warning (respectively) that includes message is diagnosed.
>
>
>
> https://godbolt.org/z/n849GPTjj
>
>
> void compile_abort() __attribute__((error("compile abort")));
>
> void compile_abort()
> {
>     __builtin_abort();
> }
>
> int main()
> {
>     compile_abort();
> }

  reply	other threads:[~2023-03-31 21:57 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-31 21:54 Jonny Grant
2023-03-31 21:57 ` Jonathan Wakely [this message]
2023-03-31 21:58 ` Xi Ruoyao
2023-03-31 22:12   ` Jonny Grant
2023-03-31 22:13     ` Xi Ruoyao
2023-04-01 16:57       ` Jonny Grant
2023-04-01 23:00         ` Jonathan Wakely
2023-04-10 23:06           ` Jonny Grant
2023-04-01 17:11 ` Warning for unsafe/insecure functions Rajeev Bansal
2023-04-01 18:50   ` Xi Ruoyao
2023-04-02  2:12     ` Rajeev Bansal

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=CAH6eHdRw48B_LnjLpgAfcct+yVwLyMGdCmgDdsKVtA4NsPXCSw@mail.gmail.com \
    --to=jwakely.gcc@gmail.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=jg@jguk.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).