summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/cpp
diff options
context:
space:
mode:
authorneil <neil@138bc75d-0d04-0410-961f-82ee72b054a4>2002-07-23 22:57:49 +0000
committerneil <neil@138bc75d-0d04-0410-961f-82ee72b054a4>2002-07-23 22:57:49 +0000
commit71a7c28254983fb0228469f2b602347a4717dfec (patch)
treed7305615fe0d53e288982b583d2c9c637deb2699 /gcc/testsuite/gcc.dg/cpp
parent44a8c9661982dea2fa5a0b8b22d96d67bdde8cc8 (diff)
downloadgcc-71a7c28254983fb0228469f2b602347a4717dfec.tar.gz
* cppexp.c (parse_defined): Mark macro used.
* cpphash.h (struct cpp_macro): New member "used". (_cpp_mark_macro_used, _cpp_warn_if_unused_macro): New. (struct cpp_reader): New member. * cppinit.c (cpp_finish_options): Set first_unused_line. (cpp_finish): Warn of unused macros if requested. (OPT_TABLE): New switches. (cpp_handle_option): Handle them. * cpplib.c (do_undef): Warn if macro unused. (do_ifdef, do_ifndef): Mark macro used. * cpplib.h (struct cpp_options): New member. * cppmacro.c (_cpp_warn_if_unused_macro): New. (enter_macro_context): Mark macro used. (_cpp_create_definition): Mark macro unused; warn if unused when redefined. * cpptrad.c (scan_out_logcial_line, push_replacement_text): Mark macros used. * doc/cppopts.texi: Update. testsuite: * gcc.dg/cpp/trad/Wunused.c, gcc.dg/cpp/trad/Wunused.h, gcc.dg/cpp/Wunused.c, gcc.dg/cpp/Wunused.h: New tests. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@55692 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/testsuite/gcc.dg/cpp')
-rw-r--r--gcc/testsuite/gcc.dg/cpp/Wunused.c32
-rw-r--r--gcc/testsuite/gcc.dg/cpp/Wunused.h1
-rw-r--r--gcc/testsuite/gcc.dg/cpp/trad/Wunused.c31
-rw-r--r--gcc/testsuite/gcc.dg/cpp/trad/Wunused.h1
4 files changed, 65 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/cpp/Wunused.c b/gcc/testsuite/gcc.dg/cpp/Wunused.c
new file mode 100644
index 00000000000..f134f55a159
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/Wunused.c
@@ -0,0 +1,32 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc. */
+
+/* { dg-do preprocess } */
+/* { dg-options -Wunused-macros } */
+
+/* Test everything related to -Wunused-macros.
+
+ Source: Neil Booth, 23 Jul 2002. */
+
+#include "Wunused.h"
+
+#define used1 /* { dg-bogus "used" } */
+#define used2 /* { dg-bogus "used" } */
+#define used3 /* { dg-bogus "used" } */
+#define used4 used4 /* { dg-bogus "used" } */
+
+#define unused5 /* { dg-warning "used" } */
+#define unused6 /* { dg-warning "used" } */
+#define unused7() /* { dg-warning "used" } */
+
+#if defined used1
+#endif
+#ifdef used2
+#endif
+#ifndef used3
+#endif
+used4
+
+unused7
+#undef unused5
+#define unused6
+unused6
diff --git a/gcc/testsuite/gcc.dg/cpp/Wunused.h b/gcc/testsuite/gcc.dg/cpp/Wunused.h
new file mode 100644
index 00000000000..8b54412bdd4
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/Wunused.h
@@ -0,0 +1 @@
+#define unused_but_ok
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/Wunused.c b/gcc/testsuite/gcc.dg/cpp/trad/Wunused.c
new file mode 100644
index 00000000000..fd81a27ecc7
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/trad/Wunused.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc. */
+
+/* { dg-do preprocess } */
+/* { dg-options "-Wunused-macros -traditional-cpp" } */
+
+/* Test everything related to -Wunused-macros.
+
+ Source: Neil Booth, 23 Jul 2002. */
+
+#include "Wunused.h"
+
+#define used1 /* { dg-bogus "used" } */
+#define used2 /* { dg-bogus "used" } */
+#define used3 /* { dg-bogus "used" } */
+#define used4 something /* { dg-bogus "used" } */
+
+#define unused5 /* { dg-warning "used" } */
+#define unused6 /* { dg-warning "used" } */
+#define unused7() /* { dg-warning "used" } */
+
+#if defined used1
+#endif
+#ifdef used2
+#endif
+#ifndef used3
+#endif
+used4
+
+#undef unused5
+#define unused6
+unused6
diff --git a/gcc/testsuite/gcc.dg/cpp/trad/Wunused.h b/gcc/testsuite/gcc.dg/cpp/trad/Wunused.h
new file mode 100644
index 00000000000..8b54412bdd4
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/trad/Wunused.h
@@ -0,0 +1 @@
+#define unused_but_ok