]> gcc.gnu.org Git - gcc.git/commitdiff
c-pragma.c (handle_pragma_token): Generate warning messages about unknown pragmas...
authorNick Clifton <nickc@cygnus.com>
Sun, 21 Dec 1997 15:24:48 +0000 (08:24 -0700)
committerJeff Law <law@gcc.gnu.org>
Sun, 21 Dec 1997 15:24:48 +0000 (08:24 -0700)
        * c-pragma.c (handle_pragma_token): Generate warning messages
        about unknown pragmas if warn_unknown_pragmas is set.
        * c-decl.c (c_decode_option): Parse -Wunknown-pragmas command
        line option to set variable: warn_unknown_pragmas.

From-SVN: r17168

gcc/ChangeLog
gcc/c-decl.c
gcc/c-pragma.c
gcc/flags.h
gcc/invoke.texi

index 517b380023411fc0e3ebc7edd71dcf70fbe9be54..6655c7aca585a10d1c854af7252d6f9a37501b2a 100644 (file)
@@ -1,3 +1,11 @@
+Sun Dec 21 16:13:55 1997  Nick Clifton  <nickc@cygnus.com
+
+       * c-pragma.c (handle_pragma_token): Generate warning messages
+       about unknown pragmas if warn_unknown_pragmas is set.
+
+       * c-decl.c (c_decode_option): Parse -Wunknown-pragmas command
+       line option to set variable: warn_unknown_pragmas.
+
 Sun Dec 21 15:51:10 1997  Manfred Hollstein  <manfred@lts.sel.alcatel.de>
 
        * m68k/mot3300.h (ASM_BYTE_OP): Don't include '\t' in the
index 895ce368bbe465b05553e949756e83c1785132ca..0bc292a51950f308e7d5fe02edf73d049cd7c70f 100644 (file)
@@ -558,6 +558,10 @@ int warn_missing_braces;
 
 int warn_main;
 
+/* Warn about #pragma directives that are not recognised.  */
+
+int warn_unknown_pragmas = 0; /* Tri state variable.  */  
+
 /* Warn about comparison of signed and unsigned values.
    If -1, neither -Wsign-compare nor -Wno-sign-compare has been specified.  */
 
@@ -763,6 +767,12 @@ c_decode_option (p)
     warn_sign_compare = 1;
   else if (!strcmp (p, "-Wno-sign-compare"))
     warn_sign_compare = 0;
+  else if (!strcmp (p, "-Wunknown-pragmas"))
+    /* Set to greater than 1, so that even unknown pragmas in system
+       headers will be warned about.  */
+    warn_unknown_pragmas = 2;
+  else if (!strcmp (p, "-Wno-unknown-pragmas"))
+    warn_unknown_pragmas = 0;
   else if (!strcmp (p, "-Wall"))
     {
       /* We save the value of warn_uninitialized, since if they put
@@ -782,6 +792,8 @@ c_decode_option (p)
       /* We set this to 2 here, but 1 in -Wmain, so -ffreestanding can turn
         it off only if it's not explicit.  */
       warn_main = 2;
+      /* Only warn about unknown pragmas that are not in system headers.  */
+      warn_unknown_pragmas = 1;
     }
   else
     return 0;
index 886c67b9828eed0f2516d2a7b7f5bb43a48a1c2c..87e060ebfdcc23d87352c79b14b4a5342e83a4b2 100644 (file)
@@ -1,5 +1,5 @@
 /* Handle #pragma, system V.4 style.  Supports #pragma weak and #pragma pack.
-   Copyright (C) 1992 Free Software Foundation, Inc.
+   Copyright (C) 1992, 1997 Free Software Foundation, Inc.
 
 This file is part of GNU CC.
 
@@ -18,8 +18,8 @@ along with GNU CC; see the file COPYING.  If not, write to
 the Free Software Foundation, 59 Temple Place - Suite 330,
 Boston, MA 02111-1307, USA.  */
 
-#include <stdio.h>
 #include "config.h"
+#include <stdio.h>
 #include "tree.h"
 #include "except.h"
 #include "function.h"
@@ -65,7 +65,7 @@ handle_pragma_token (string, token)
          if (HANDLE_PRAGMA_WEAK)
            handle_pragma_weak (state, name, value);
 
-#endif /* HANDLE_PRAMA_WEAK */
+#endif /* HANDLE_PRAGMA_WEAK */
        }
 
       type = state = ps_start;
@@ -82,7 +82,16 @@ handle_pragma_token (string, token)
          else if (strcmp (IDENTIFIER_POINTER (token), "weak") == 0)
            type = state = ps_weak;
          else
-           type = state = ps_done;
+           {
+             type = state = ps_done;
+
+             /* Issue a warning message if we have been asked to do so.
+                Ignoring unknown pragmas in system header file unless          
+                an explcit -Wunknown-pragmas has been given. */                
+             if (warn_unknown_pragmas > 1
+                 || (warn_unknown_pragmas && ! in_system_header))
+               warning ("ignoring pragma: %s", string);
+           }
        }
       else
        type = state = ps_done;
index ba057204dede483656eeeb5295fb2bb532ee5b32..43c88c94e18dbb002f98c3ce5cdd6d78c4211adc 100644 (file)
@@ -83,6 +83,14 @@ extern int warn_inline;
 
 extern int warn_uninitialized;
 
+/* Zero if unknown pragmas are ignored
+   One if the compiler should warn about an unknown pragma not in
+   a system include file.
+   Greater than one if the compiler should warn for all unknown
+   pragmas.  */
+
+extern int warn_unknown_pragmas;
+
 /* Nonzero means warn about all declarations which shadow others.   */
 
 extern int warn_shadow;
index f8c9f9af3f95f4c824e61f22f97403531a49abf7..d1f8756c4177cd16f5453c090e2506d2a01440d0 100644 (file)
@@ -126,6 +126,7 @@ in the following sections.
 -Wsign-compare  -Wstrict-prototypes  -Wswitch  -Wsynth
 -Wtemplate-debugging  -Wtraditional  -Wtrigraphs
 -Wundef  -Wuninitialized  -Wunused  -Wwrite-strings
+-Wunknown-pragmas
 @end smallexample
 
 @item Debugging Options
@@ -1400,6 +1401,15 @@ members.
 When using templates in a C++ program, warn if debugging is not yet
 fully available (C++ only).
 
+@item -Wunknown-pragmas
+@cindex warning for unknown pragmas
+@cindex unknown pragmas, warning
+@cindex pragmas, warning of unknown
+Warn when a #pragma directive is encountered which is not understood by
+GCC.  If this command line option is used, warnings will even be issued
+for unknown pragmas in system header files.  This is not the case if
+the warnings were only enabled by the @samp{-Wall} command line option.
+
 @item -Wall
 All of the above @samp{-W} options combined.  This enables all the
 warnings about constructions that some users consider questionable, and
This page took 0.089581 seconds and 5 git commands to generate.