public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-1435] c-family: Add fix-it suggestions for more <stdlib.h> names [PR101052]
Date: Mon, 14 Jun 2021 17:24:25 +0000 (GMT)	[thread overview]
Message-ID: <20210614172425.E10E5395542C@sourceware.org> (raw)

https://gcc.gnu.org/g:93bfadf3a1db7d73e9ca4a4a3d40f7f81ea16d39

commit r12-1435-g93bfadf3a1db7d73e9ca4a4a3d40f7f81ea16d39
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Mon Jun 14 11:38:11 2021 +0100

    c-family: Add fix-it suggestions for more <stdlib.h> names [PR101052]
    
            PR c++/101052
    
    gcc/c-family/ChangeLog:
    
            * known-headers.cc (get_stdlib_header_for_name): Add known
            headers for EXIT_FAILURE, EXIT_SUCCESS, abort, atexit, calloc,
            exit, and getenv.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/spellcheck-stdlib.C: Add checks for <cstdlib> names.
            * gcc.dg/spellcheck-stdlib.c: Likewise.

Diff:
---
 gcc/c-family/known-headers.cc            |  7 +++++++
 gcc/testsuite/g++.dg/spellcheck-stdlib.C | 18 ++++++++++++++++++
 gcc/testsuite/gcc.dg/spellcheck-stdlib.c | 10 ++++++++++
 3 files changed, 35 insertions(+)

diff --git a/gcc/c-family/known-headers.cc b/gcc/c-family/known-headers.cc
index 85924718c8b..a3912468a8d 100644
--- a/gcc/c-family/known-headers.cc
+++ b/gcc/c-family/known-headers.cc
@@ -162,7 +162,14 @@ get_stdlib_header_for_name (const char *name, enum stdlib lib)
     {"stdout", {"<stdio.h>", "<cstdio>"} },
 
     /* <stdlib.h> and <cstdlib>.  */
+    {"EXIT_FAILURE", {"<stdlib.h>", "<cstdlib>"} },
+    {"EXIT_SUCCESS", {"<stdlib.h>", "<cstdlib>"} },
+    {"abort", {"<stdlib.h>", "<cstdlib>"} },
+    {"atexit", {"<stdlib.h>", "<cstdlib>"} },
+    {"calloc", {"<stdlib.h>", "<cstdlib>"} },
+    {"exit", {"<stdlib.h>", "<cstdlib>"} },
     {"free", {"<stdlib.h>", "<cstdlib>"} },
+    {"getenv", {"<stdlib.h>", "<cstdlib>"} },
     {"malloc", {"<stdlib.h>", "<cstdlib>"} },
     {"realloc", {"<stdlib.h>", "<cstdlib>"} },
 
diff --git a/gcc/testsuite/g++.dg/spellcheck-stdlib.C b/gcc/testsuite/g++.dg/spellcheck-stdlib.C
index 31e91fe8d1b..87736b25e54 100644
--- a/gcc/testsuite/g++.dg/spellcheck-stdlib.C
+++ b/gcc/testsuite/g++.dg/spellcheck-stdlib.C
@@ -138,6 +138,24 @@ void test_cstdlib (void *q)
   // { dg-message "'#include <cstdlib>'" "" { target *-*-* } .-1 }
   q = realloc (q, 1024); // { dg-error "was not declared" }
   // { dg-message "'#include <cstdlib>'" "" { target *-*-* } .-1 }
+  q = calloc (8, 8); // { dg-error "was not declared" }
+  // { dg-message "'#include <cstdlib>'" "" { target *-*-* } .-1 }
+
+  void callback ();
+  atexit (callback); // { dg-error "was not declared" }
+  // { dg-message "'#include <cstdlib>'" "" { target *-*-* } .-1 }
+  int i;
+  i = EXIT_SUCCESS; // { dg-error "was not declared" }
+  // { dg-message "'#include <cstdlib>'" "" { target *-*-* } .-1 }
+  i = EXIT_FAILURE; // { dg-error "was not declared" }
+  // { dg-message "'#include <cstdlib>'" "" { target *-*-* } .-1 }
+  exit (i); // { dg-error "was not declared" }
+  // { dg-message "'#include <cstdlib>'" "" { target *-*-* } .-1 }
+  abort (); // { dg-error "was not declared" }
+  // { dg-message "'#include <cstdlib>'" "" { target *-*-* } .-1 }
+
+  getenv ("foo"); // { dg-error "was not declared" }
+  // { dg-message "'#include <cstdlib>'" "" { target *-*-* } .-1 }
 }
 
 /* Verify that we don't offer suggestions to stdlib globals names when
diff --git a/gcc/testsuite/gcc.dg/spellcheck-stdlib.c b/gcc/testsuite/gcc.dg/spellcheck-stdlib.c
index 1ae3b5e33ab..7297a92368f 100644
--- a/gcc/testsuite/gcc.dg/spellcheck-stdlib.c
+++ b/gcc/testsuite/gcc.dg/spellcheck-stdlib.c
@@ -38,6 +38,16 @@ void test_stdio_h (void)
   /* { dg-message "'EOF' is defined in header '<stdio.h>'; did you forget to '#include <stdio.h>'?" "" { target *-*-* } .-1 } */
 }
 
+/* Missing <stdlib.h>.  */
+
+void test_stdlib (int i)
+{
+  i = EXIT_SUCCESS; /* { dg-error "'EXIT_SUCCESS' undeclared" } */
+  /* { dg-message "'EXIT_SUCCESS' is defined in header '<stdlib.h>'; did you forget to '#include <stdlib.h>'?" "" { target *-*-* } .-1 } */
+  i = EXIT_FAILURE; /* { dg-error "'EXIT_FAILURE' undeclared" } */
+  /* { dg-message "'EXIT_FAILURE' is defined in header '<stdlib.h>'; did you forget to '#include <stdlib.h>'?" "" { target *-*-* } .-1 } */
+}
+
 /* Missing <errno.h>.  */
 
 int test_errno_h (void)


                 reply	other threads:[~2021-06-14 17:24 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210614172425.E10E5395542C@sourceware.org \
    --to=redi@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).