• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/toolchains/hndtools-armeabi-2013.11/share/doc/arm-arm-none-eabi/html/gcc/
1<html lang="en">
2<head>
3<title>Diagnostic Pragmas - Using the GNU Compiler Collection (GCC)</title>
4<meta http-equiv="Content-Type" content="text/html">
5<meta name="description" content="Using the GNU Compiler Collection (GCC)">
6<meta name="generator" content="makeinfo 4.13">
7<link title="Top" rel="start" href="index.html#Top">
8<link rel="up" href="Pragmas.html#Pragmas" title="Pragmas">
9<link rel="prev" href="Weak-Pragmas.html#Weak-Pragmas" title="Weak Pragmas">
10<link rel="next" href="Visibility-Pragmas.html#Visibility-Pragmas" title="Visibility Pragmas">
11<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
12<!--
13Copyright (C) 1988-2013 Free Software Foundation, Inc.
14
15Permission is granted to copy, distribute and/or modify this document
16under the terms of the GNU Free Documentation License, Version 1.3 or
17any later version published by the Free Software Foundation; with the
18Invariant Sections being ``Funding Free Software'', the Front-Cover
19Texts being (a) (see below), and with the Back-Cover Texts being (b)
20(see below).  A copy of the license is included in the section entitled
21``GNU Free Documentation License''.
22
23(a) The FSF's Front-Cover Text is:
24
25     A GNU Manual
26
27(b) The FSF's Back-Cover Text is:
28
29     You have freedom to copy and modify this GNU Manual, like GNU
30     software.  Copies published by the Free Software Foundation raise
31     funds for GNU development.-->
32<meta http-equiv="Content-Style-Type" content="text/css">
33<style type="text/css"><!--
34  pre.display { font-family:inherit }
35  pre.format  { font-family:inherit }
36  pre.smalldisplay { font-family:inherit; font-size:smaller }
37  pre.smallformat  { font-family:inherit; font-size:smaller }
38  pre.smallexample { font-size:smaller }
39  pre.smalllisp    { font-size:smaller }
40  span.sc    { font-variant:small-caps }
41  span.roman { font-family:serif; font-weight:normal; } 
42  span.sansserif { font-family:sans-serif; font-weight:normal; } 
43--></style>
44<link rel="stylesheet" type="text/css" href="../cs.css">
45</head>
46<body>
47<div class="node">
48<a name="Diagnostic-Pragmas"></a>
49<p>
50Next:&nbsp;<a rel="next" accesskey="n" href="Visibility-Pragmas.html#Visibility-Pragmas">Visibility Pragmas</a>,
51Previous:&nbsp;<a rel="previous" accesskey="p" href="Weak-Pragmas.html#Weak-Pragmas">Weak Pragmas</a>,
52Up:&nbsp;<a rel="up" accesskey="u" href="Pragmas.html#Pragmas">Pragmas</a>
53<hr>
54</div>
55
56<h4 class="subsection">6.58.10 Diagnostic Pragmas</h4>
57
58<p>GCC allows the user to selectively enable or disable certain types of
59diagnostics, and change the kind of the diagnostic.  For example, a
60project's policy might require that all sources compile with
61<samp><span class="option">-Werror</span></samp> but certain files might have exceptions allowing
62specific types of warnings.  Or, a project might selectively enable
63diagnostics and treat them as errors depending on which preprocessor
64macros are defined.
65
66     <dl>
67<dt><code>#pragma GCC diagnostic </code><var>kind</var> <var>option</var><dd><a name="index-pragma_002c-diagnostic-3481"></a>
68Modifies the disposition of a diagnostic.  Note that not all
69diagnostics are modifiable; at the moment only warnings (normally
70controlled by &lsquo;<samp><span class="samp">-W...</span></samp>&rsquo;) can be controlled, and not all of them. 
71Use <samp><span class="option">-fdiagnostics-show-option</span></samp> to determine which diagnostics
72are controllable and which option controls them.
73
74     <p><var>kind</var> is &lsquo;<samp><span class="samp">error</span></samp>&rsquo; to treat this diagnostic as an error,
75&lsquo;<samp><span class="samp">warning</span></samp>&rsquo; to treat it like a warning (even if <samp><span class="option">-Werror</span></samp> is
76in effect), or &lsquo;<samp><span class="samp">ignored</span></samp>&rsquo; if the diagnostic is to be ignored. 
77<var>option</var> is a double quoted string that matches the command-line
78option.
79
80     <pre class="smallexample">          #pragma GCC diagnostic warning "-Wformat"
81          #pragma GCC diagnostic error "-Wformat"
82          #pragma GCC diagnostic ignored "-Wformat"
83</pre>
84     <p>Note that these pragmas override any command-line options.  GCC keeps
85track of the location of each pragma, and issues diagnostics according
86to the state as of that point in the source file.  Thus, pragmas occurring
87after a line do not affect diagnostics caused by that line.
88
89     <br><dt><code>#pragma GCC diagnostic push</code><dt><code>#pragma GCC diagnostic pop</code><dd>
90Causes GCC to remember the state of the diagnostics as of each
91<code>push</code>, and restore to that point at each <code>pop</code>.  If a
92<code>pop</code> has no matching <code>push</code>, the command-line options are
93restored.
94
95     <pre class="smallexample">          #pragma GCC diagnostic error "-Wuninitialized"
96            foo(a);                       /* error is given for this one */
97          #pragma GCC diagnostic push
98          #pragma GCC diagnostic ignored "-Wuninitialized"
99            foo(b);                       /* no diagnostic for this one */
100          #pragma GCC diagnostic pop
101            foo(c);                       /* error is given for this one */
102          #pragma GCC diagnostic pop
103            foo(d);                       /* depends on command-line options */
104</pre>
105     </dl>
106
107 <p>GCC also offers a simple mechanism for printing messages during
108compilation.
109
110     <dl>
111<dt><code>#pragma message </code><var>string</var><dd><a name="index-pragma_002c-diagnostic-3482"></a>
112Prints <var>string</var> as a compiler message on compilation.  The message
113is informational only, and is neither a compilation warning nor an error.
114
115     <pre class="smallexample">          #pragma message "Compiling " __FILE__ "..."
116</pre>
117     <p><var>string</var> may be parenthesized, and is printed with location
118information.  For example,
119
120     <pre class="smallexample">          #define DO_PRAGMA(x) _Pragma (#x)
121          #define TODO(x) DO_PRAGMA(message ("TODO - " #x))
122          
123          TODO(Remember to fix this)
124</pre>
125     <p class="noindent">prints &lsquo;<samp><span class="samp">/tmp/file.c:4: note: #pragma message:
126TODO - Remember to fix this</span></samp>&rsquo;.
127
128 </dl>
129
130 </body></html>
131
132