Would be great if the suggestions could suggest <stdlib.h> for rand() Same in C and C++
Confirmed. Simple testcase: int f(void) { return rand(); }
diff --git a/gcc/c-family/known-headers.cc b/gcc/c-family/known-headers.cc index 9c256173b82..dd4c23e5923 100644 --- a/gcc/c-family/known-headers.cc +++ b/gcc/c-family/known-headers.cc @@ -171,6 +171,8 @@ get_stdlib_header_for_name (const char *name, enum stdlib lib) {"getenv", {"<stdlib.h>", "<cstdlib>"} }, {"malloc", {"<stdlib.h>", "<cstdlib>"} }, {"realloc", {"<stdlib.h>", "<cstdlib>"} }, + {"rand", {"<stdlib.h>", "<cstdlib>"} }, + {"srand", {"<stdlib.h>", "<cstdlib>"} }, /* <string.h> and <cstring>. */ {"memchr", {"<string.h>", "<cstring>"} }, Should be enough for both C and C++.
Great! I just saw it is the same for random(), srandom(), initstate(), setstate() Is there an easy way to add them all based on the C API to save opening separate tickets? I added those : From 6ff344979af46dbcd739dd9068d6d595547e4c27 Mon Sep 17 00:00:00 2001 From: Jonathan Grant <jg@jguk.org> Date: Sun, 25 Dec 2022 22:38:44 +0000 Subject: [PATCH] add srandom random initstate setstate --- gcc/c-family/known-headers.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gcc/c-family/known-headers.cc b/gcc/c-family/known-headers.cc index 9c256173b82..ade9fa2dcc0 100644 --- a/gcc/c-family/known-headers.cc +++ b/gcc/c-family/known-headers.cc @@ -171,6 +171,10 @@ get_stdlib_header_for_name (const char *name, enum stdlib lib) {"getenv", {"<stdlib.h>", "<cstdlib>"} }, {"malloc", {"<stdlib.h>", "<cstdlib>"} }, {"realloc", {"<stdlib.h>", "<cstdlib>"} }, + {"random", {"<stdlib.h>", "<cstdlib>"} }, + {"srandom", {"<stdlib.h>", "<cstdlib>"} }, + {"initstate", {"<stdlib.h>", "<cstdlib>"} }, + {"setstate", {"<stdlib.h>", "<cstdlib>"} }, /* <string.h> and <cstring>. */ {"memchr", {"<string.h>", "<cstring>"} }, -- 2.37.2
(In reply to Jonny Grant from comment #3) > Great! I just saw it is the same for random(), srandom(), initstate(), > setstate() > > Is there an easy way to add them all based on the C API to save opening > separate tickets? > > I added those : Could you send the patch to gcc-patches (the mailing list)? Thanks.
(In reply to Sam James from comment #4) > (In reply to Jonny Grant from comment #3) > > Great! I just saw it is the same for random(), srandom(), initstate(), > > setstate() > > > > Is there an easy way to add them all based on the C API to save opening > > separate tickets? > > > > I added those : > > Could you send the patch to gcc-patches (the mailing list)? Thanks. Sure, just sent :-)
https://inbox.sourceware.org/gcc-patches/881e795d-34c8-0445-74cf-cb68192d2dfe@jguk.org/