https://bugs.llvm.org/show_bug.cgi?id=40417
Bug ID: 40417
Summary: diagnose_if should try harder to find violations
Product: clang
Version: unspecified
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: -New Bugs
Assignee: unassignedclangb...@nondot.org
Reporter: redbeard0...@gmail.com
CC: htmldevelo...@gmail.com, llvm-bugs@lists.llvm.org,
neeil...@live.com, richard-l...@metafoo.co.uk
This code compiles without warnings, even though (at least with -O2) the
compiler clearly knows that that there are violations since it is emitting
unchecked calls to boom(). This makes this feature much less useful since it
can only catch direct violations, which are the most likely to be noticed by
humans. It would be much more useful as a general static analysis hint if some
of these other cases could also be detected and warned on. The last example is
particularly interesting to us because it is a slightly simplified version of
where we tried to use diagnose_if until we saw that it was unable to detect
anything.
https://godbolt.org/z/QfCCux
void boom();
inline void semi_static_assert(bool arg)
__attribute__((diagnose_if(!arg, "boom", "warning"))) {
if (!arg) boom();
}
inline bool always_false() {return false;}
struct bool_holder {
bool is_true() const { return b; }
bool b;
};
void test() {
// semi_static_assert(false); // warns
// no warnings from the rest
semi_static_assert(always_false());
bool also_false = false;
semi_static_assert(also_false);
semi_static_assert(bool_holder{false}.is_true());
}
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs