mirror of
https://github.com/llvm/llvm-project.git
synced 2025-05-01 13:26:09 +00:00

Warn in cases such as "x + someCondition ? 42 : 0;", where the condition expression looks arithmetic, and has a right-hand side that looks boolean. This (partly) addresses http://llvm.org/bugs/show_bug.cgi?id=9969 llvm-svn: 132565
19 lines
1.2 KiB
C++
19 lines
1.2 KiB
C++
// RUN: %clang_cc1 -Wparentheses -fsyntax-only -verify %s
|
|
// RUN: %clang_cc1 -Wparentheses -fixit %s -o - | %clang_cc1 -Wparentheses -Werror -
|
|
|
|
bool someConditionFunc();
|
|
|
|
void conditional_op(int x, int y, bool b) {
|
|
(void)(x + someConditionFunc() ? 1 : 2); // expected-warning {{?: has lower precedence than +}} \
|
|
// expected-note {{place parentheses around the ?: expression to evaluate it first}} \
|
|
// expected-note {{place parentheses around the + expression to silence this warning}}
|
|
|
|
(void)(x - b ? 1 : 2); // expected-warning {{?: has lower precedence than -}} \
|
|
// expected-note {{place parentheses around the ?: expression to evaluate it first}} \
|
|
// expected-note {{place parentheses around the - expression to silence this warning}}
|
|
|
|
(void)(x * (x == y) ? 1 : 2); // expected-warning {{?: has lower precedence than *}} \
|
|
// expected-note {{place parentheses around the ?: expression to evaluate it first}} \
|
|
// expected-note {{place parentheses around the * expression to silence this warning}}
|
|
}
|