[llvm-bugs] [Bug 44319] New: warnings promoted to error via pragma can not be demoted to warning via pragma
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Dec 17 03:01:54 PST 2019
https://bugs.llvm.org/show_bug.cgi?id=44319
Bug ID: 44319
Summary: warnings promoted to error via pragma can not be
demoted to warning via pragma
Product: clang
Version: unspecified
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P
Component: -New Bugs
Assignee: unassignedclangbugs at nondot.org
Reporter: oliverhorn at gmx.com
CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
neeilans at live.com, richard-llvm at metafoo.co.uk
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
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20191217/8b27733c/attachment.html>
More information about the llvm-bugs
mailing list