Note that there are some explanatory texts on larger screens.

plurals
  1. POStrange diagnostic pragma behavior in GCC 4.6
    primarykey
    data
    text
    <p>I have a C program with a couple of static functions that are not (yet) used. I want to disable warnings for those specific functions. I do not want to disable all <code>-Wunused-function</code> warnings. I am using GCC 4.6. Specifically:</p> <pre><code>ek@Apok:~/source$ gcc --version gcc (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1 Copyright (C) 2011 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. </code></pre> <p>I am following the advice in the documentation (to use <code>push</code> and <code>pop</code>), but I have not been able to get it to work.</p> <p>I have created some simplified source code to investigate the problem. I am compiling them with <code>gcc -Wall -o pragma pragma.c</code> (where <code>pragma.c</code>). My first version of <code>pragma.c</code> looks like this:</p> <pre><code>void foo(int i) { } static void bar() { } int main() { return 0; } </code></pre> <p>As expected, I get this when I compile it:</p> <pre><code>pragma.c:3:13: warning: ‘bar’ defined but not used [-Wunused-function] </code></pre> <p>Also as expected, I am able to disable the warning like this (then the compile succeeds silently):</p> <pre><code>#pragma GCC diagnostic ignored "-Wunused-function" void foo(int i) { } static void bar() { } int main() { return 0; } </code></pre> <p>But then, I tried this:</p> <pre><code>void foo(int i) { } #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-function" static void bar() { } #pragma GCC diagnostic pop int main() { return 0; } </code></pre> <p>When I compiled that, I got the original warning:</p> <pre><code>pragma.c:4:13: warning: ‘bar’ defined but not used [-Wunused-function] </code></pre> <p>Removing the <code>pop</code> gets rid of the warning:</p> <pre><code>void foo(int i) { } #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-function" static void bar() { } int main() { return 0; } </code></pre> <p>But I need a way to disable the warning just for a specific section of code. I have not been able to do that.</p> <p>It is hard for me to imagine how this could be intended behavior...but many others have used this version of GCC and it seems unlikely that, if this were a bug, it would make it into the release version.</p> <p>Still, I have trouble seeing how this behavior is consistent with the documentation, which says that "pragmas occurring after a line do not affect diagnostics caused by that line."</p> <p>Does anyone know what I am doing wrong? (Or, if nothing, does anyone have more information about the problem, such as a link to a bug report and/or information about possible workarounds.)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload