// Empty DiagGroups are recognized by clang but ignored.
def : DiagGroup<"abi">;
def AbsoluteValue : DiagGroup<"absolute-value">;
-def : DiagGroup<"address">;
def AddressOfTemporary : DiagGroup<"address-of-temporary">;
def : DiagGroup<"aggregate-return">;
def GNUAlignofExpression : DiagGroup<"gnu-alignof-expression">;
def LiteralConversion : DiagGroup<"literal-conversion">;
def StringConversion : DiagGroup<"string-conversion">;
def SignConversion : DiagGroup<"sign-conversion">;
-def BoolConversion : DiagGroup<"bool-conversion">;
+def PointerBoolConversion : DiagGroup<"pointer-bool-conversion">;
+def BoolConversion : DiagGroup<"bool-conversion", [ PointerBoolConversion ] >;
def IntConversion : DiagGroup<"int-conversion">;
def EnumConversion : DiagGroup<"enum-conversion">;
def EnumTooLarge : DiagGroup<"enum-too-large">;
def GNUStaticFloatInit : DiagGroup<"gnu-static-float-init">;
def StaticFloatInit : DiagGroup<"static-float-init", [GNUStaticFloatInit]>;
def GNUStatementExpression : DiagGroup<"gnu-statement-expression">;
+def StringCompare : DiagGroup<"string-compare">;
def StringPlusInt : DiagGroup<"string-plus-int">;
def StringPlusChar : DiagGroup<"string-plus-char">;
def StrncatSize : DiagGroup<"strncat-size">;
// Aggregation warning settings.
+// Populate -Waddress with warnings from other groups.
+def : DiagGroup<"address", [PointerBoolConversion,
+ StringCompare,
+ TautologicalPointerCompare]>;
+
// -Widiomatic-parentheses contains warnings about 'idiomatic'
// missing parentheses; it is off by default. We do not include it
// in -Wparentheses because most users who use -Wparentheses explicitly
def warn_impcast_pointer_to_bool : Warning<
"address of%select{| function| array}0 '%1' will always evaluate to "
"'true'">,
- InGroup<BoolConversion>;
+ InGroup<PointerBoolConversion>;
def warn_null_pointer_compare : Warning<
"comparison of %select{address of|function|array}0 '%1' %select{not |}2"
"equal to a null pointer is always %select{true|false}2">,
def warn_stringcompare : Warning<
"result of comparison against %select{a string literal|@encode}0 is "
"unspecified (use strncmp instead)">,
- InGroup<DiagGroup<"string-compare">>;
+ InGroup<StringCompare>;
def warn_identity_field_assign : Warning<
"assigning %select{field|instance variable}0 to itself">,
--- /dev/null
+// RUN: %clang_cc1 -fsyntax-only -verify -Wno-bool-conversion -Wno-string-compare -Wno-tautological-compare -Waddress %s
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+void foo();
+int arr[5];
+int global;
+const char* str = "";
+
+void test() {
+ if (foo) {} // expected-warning{{always evaluate to 'true'}} \
+ // expected-note{{silence}}
+ if (arr) {} // expected-warning{{always evaluate to 'true'}}
+ if (&global) {} // expected-warning{{always evaluate to 'true'}}
+ if (foo == 0) {} // expected-warning{{always false}} \
+ // expected-note{{silence}}
+ if (arr == 0) {} // expected-warning{{always false}}
+ if (&global == 0) {} // expected-warning{{always false}}
+
+ if (str == "foo") {} // expected-warning{{unspecified}}
+}