Scoped attribute directive ignored diagnostic (false positive?)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi!

I'm seeing the following diagnostics, and I don't know if I'm doing
something wrong, or if the compiler is going crazy.

Could you please explain what's wrong with this code?

Thanks!
And have a lovely day,
Alex


alx@devuan:~/tmp/gcc$ cat strsep2arr.c 
#include <errno.h>
#include <stddef.h>
#include <string.h>
#include <sys/types.h>

[[gnu::access(read_write, 1)]]
[[gnu::access(write_only, 4)]]
[[gnu::null_terminated_string_arg(1)]]
[[gnu::null_terminated_string_arg(2)]]
inline ssize_t strsep2arr(char *s, const char *restrict delim,
    size_t n, char *a[restrict n]);

// strsep(3) a string into an array of strings.
// Return the number of fields in the string, or -1 on error.
inline ssize_t strsep2arr(char *s, const char *restrict delim,
    size_t n, char *a[restrict n])
{
	size_t  i;

	for (i = 0; i < n && s != NULL; i++)
		a[i] = strsep(&s, delim);

	if (s != NULL) {
		errno = E2BIG;
		return -1;
	}

	return i;
}
alx@devuan:~/tmp/gcc$ gcc -Wall -Wextra strsep2arr.c -S
strsep2arr.c:11:5: warning: ‘gnu::null_terminated_string_arg’ scoped attribute directive ignored [-Wattributes]
   11 |     size_t n, char *a[restrict n]);
      |     ^~~~~~
strsep2arr.c:11:5: warning: ‘gnu::null_terminated_string_arg’ scoped attribute directive ignored [-Wattributes]
strsep2arr.c:10:16: warning: attribute ‘access (write_only, 4)’ positional argument 2 missing in previous designation [-Wattributes]
   10 | inline ssize_t strsep2arr(char *s, const char *restrict delim,
      |                ^~~~~~~~~~
strsep2arr.c:11:12: note: designating the bound of variable length array argument 4
   11 |     size_t n, char *a[restrict n]);
      |     ~~~~~~~^  ~~~~~~~~~~~~~~~~~~~
strsep2arr.c:16:21: warning: argument 4 of type ‘char *[restrict  n]’ declared as a variable length array [-Wvla-parameter]
   16 |     size_t n, char *a[restrict n])
      |               ~~~~~~^~~~~~~~~~~~~
strsep2arr.c:11:21: note: previously declared as an ordinary array ‘char *[restrict]’
   11 |     size_t n, char *a[restrict n]);
      |               ~~~~~~^~~~~~~~~~~~~
strsep2arr.c: In function ‘strsep2arr’:
strsep2arr.c:15:16: warning: attribute ‘access (write_only, 4)’ positional argument 2 missing in previous designation [-Wattributes]
   15 | inline ssize_t strsep2arr(char *s, const char *restrict delim,
      |                ^~~~~~~~~~
strsep2arr.c:16:12: note: designating the bound of variable length array argument 4
   11 |     size_t n, char *a[restrict n]);
      |               ~~~~~~~~~~~~~~~~~~~
......
   16 |     size_t n, char *a[restrict n])
      |     ~~~~~~~^
alx@devuan:~/tmp/gcc$ gcc --version
gcc (Debian 12.2.0-14) 12.2.0
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.



-- 
<https://www.alejandro-colomar.es/>

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux