https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126264

            Bug ID: 126264
           Summary: attribute error is ignored with invalid param
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jg at jguk dot org
  Target Milestone: ---

Should this be a build error?

A string literal is required by  __attribute__ error ("message")

But it is ignored if is NULL, should this be a build error?
clang gives a build error

$ clang -std=c2x -Wall -O3 -o error error.c
error.c:4:36: error: expected string literal as argument of 'error' attribute
    4 | void _fail() __attribute__ ((error(NULL)));
      |                                    ^

$ clang -std=c2x -Wall -O3 -o error error.c
error.c:4:36: error: expected string literal as argument of 'error' attribute
    4 | void _fail() __attribute__ ((error(nullptr)));



https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/Common-Attributes.html


<source>:4:1: warning: 'error' attribute ignored [-Wattributes]
    4 | void _fail() __attribute__ ((error(NULL)));
      | ^~~~


https://godbolt.org/z/53YYq6f8Y

// gcc -std=c20 -Wall -O3 -o error error.c
#include <stddef.h>

void _fail() __attribute__ ((error(NULL)));

int main()
{
    _fail();
}



clang also gives a build error if the string is invalid - should gcc check the
string-literal is valid too?

j$ clang -std=c2x -Wall -O3 -o error error.c
error.c:4:37: error: invalid escape sequence '\01' in an unevaluated string
literal
    4 | void _fail() __attribute__ ((error("\01")));

Reply via email to