__attribute__ error ("message")
Jonathan Wakely
jwakely.gcc@gmail.com
Fri Mar 31 21:57:42 GMT 2023
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();
> }
More information about the Gcc-help
mailing list