<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - warnings promoted to error via pragma can not be demoted to warning via pragma"
   href="https://bugs.llvm.org/show_bug.cgi?id=44319">44319</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>warnings promoted to error via pragma can not be demoted to warning via pragma
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>-New Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>oliverhorn@gmx.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Hello,

In the following piece of code Clang throws an error for the unused variable
even though it should only be a warning.

void func()
{
#pragma clang diagnostic error "-Wunused-variable"
#pragma clang diagnostic warning "-Wunused-variable"
    int a = 0;
}

The above example of course does not make much sense, but the warning option
could have been set to error in an included file or in the same file somewhere
earlier.

According to a test within godbolt.org this broke with Clang 3.1 (it is a
warning on Clang 3.0).

A workaround is to demote the warning flag to ignored and then promote to
warning again.

void func()
{
#pragma clang diagnostic error "-Wunused-variable"
#pragma clang diagnostic ignored "-Wunused-variable"
#pragma clang diagnostic warning "-Wunused-variable"
    int a = 0;
}

Compiling the following code with -Wunused-variable -Werror as command line
options works:

void func()
{
#pragma clang diagnostic warning "-Wunused-variable"
    int a = 0;
}

In GCC it works without the ignore as expected.

void func()
{
#pragma GCC diagnostic error "-Wunused-variable"
#pragma GCC diagnostic warning "-Wunused-variable"
    int a = 0;
}

Kind regards,
Oliver</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>