I have tried and failed to reproduce the statement in the question: My test program builds without issues.
I looked up the unshare(2) man page and found
SYNOPSIS
#define _GNU_SOURCE
#include <sched.h>
int unshare(int flags);
so I wrote a small test program
#define _GNU_SOURCE
#include <sched.h>
int main(void)
{
unshare(123);
return 0;
}
which I then built with all warnings enabled and treated as errors:
$ gcc -std=c11 -pedantic -Wall -Wextra -Werror -o unshare-ex unshare-ex.c
$ _
without any problems.
So I rebuilt the program with
$ gcc -g -O2 -save-temps=obj -std=c11 -pedantic -Wall -Wextra -Werror -o unshare-ex unshare-ex.c
$ _
and took a look at unshare-ex.i to trace the include files. As it turns out, /usr/include/sched.h eventually includes /usr/include/bits/sched.h which contains the definition of the unshare() function which expands to
extern int unshare (int __flags) __attribute__ ((__nothrow__ , __leaf__));
but is written in /usr/include/bits/sched.h as
extern int unshare (int __flags) __THROW;
I am not sure what the problem is here.
FWIW, both /usr/include/sched.h and /usr/include/bits/sched.h are shipped as part of the glibc-headers-x86-2.35-15.fc36.noarch package here.