summaryrefslogtreecommitdiff
path: root/test/SemaTemplate
diff options
context:
space:
mode:
authorRichard Trieu <rtrieu@google.com>2014-02-26 02:36:06 +0000
committerRichard Trieu <rtrieu@google.com>2014-02-26 02:36:06 +0000
commit2a66e6e50046e6b9ae048f114ad4fec23011e93c (patch)
tree6c3d809f806b0d53a9c0a9ed9946a2f674cfef53 /test/SemaTemplate
parente1805368a8a09000b3be70b50e20522efb78581e (diff)
downloadclang-2a66e6e50046e6b9ae048f114ad4fec23011e93c.tar.gz
PR16074, implement warnings to catch pointer to boolean true and pointer to
null comparison when the pointer is known to be non-null. This catches the array to pointer decay, function to pointer decay and address of variables. This does not catch address of function since this has been previously used to silence a warning. Pointer to bool conversion is under -Wbool-conversion. Pointer to null comparison is under -Wtautological-pointer-compare, a sub-group of -Wtautological-compare. void foo() { int arr[5]; int x; // warn on these conditionals if (foo); if (arr); if (&x); if (foo == null); if (arr == null); if (&x == null); if (&foo); // no warning } git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@202216 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/SemaTemplate')
-rw-r--r--test/SemaTemplate/resolve-single-template-id.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/test/SemaTemplate/resolve-single-template-id.cpp b/test/SemaTemplate/resolve-single-template-id.cpp
index 7fb16eb467..915c42c85a 100644
--- a/test/SemaTemplate/resolve-single-template-id.cpp
+++ b/test/SemaTemplate/resolve-single-template-id.cpp
@@ -45,9 +45,15 @@ int main()
+oneT<int>; // expected-warning {{expression result unused}}
-oneT<int>; //expected-error {{invalid argument type}}
oneT<int> == 0; // expected-warning {{equality comparison result unused}} \
- // expected-note {{use '=' to turn this equality comparison into an assignment}}
- 0 == oneT<int>; // expected-warning {{equality comparison result unused}}
- 0 != oneT<int>; // expected-warning {{inequality comparison result unused}}
+ // expected-note {{use '=' to turn this equality comparison into an assignment}} \
+ // expected-warning {{comparison of function 'oneT<int>' equal to a null pointer is always false}} \
+ // expected-note {{prefix with the address-of operator to silence this warning}}
+ 0 == oneT<int>; // expected-warning {{equality comparison result unused}} \
+ // expected-warning {{comparison of function 'oneT<int>' equal to a null pointer is always false}} \
+ // expected-note {{prefix with the address-of operator to silence this warning}}
+ 0 != oneT<int>; // expected-warning {{inequality comparison result unused}} \
+ // expected-warning {{comparison of function 'oneT<int>' not equal to a null pointer is always true}} \
+ // expected-note {{prefix with the address-of operator to silence this warning}}
(false ? one : oneT<int>); // expected-warning {{expression result unused}}
void (*p1)(int); p1 = oneT<int>;
@@ -69,7 +75,9 @@ int main()
two < two; //expected-error 2 {{reference to overloaded function could not be resolved; did you mean to call it with no arguments?}} expected-error {{invalid operands to binary expression ('void' and 'void')}}
twoT<int> < twoT<int>; //expected-error {{reference to overloaded function could not be resolved; did you mean to call it?}} {{cannot resolve overloaded function 'twoT' from context}}
oneT<int> == 0; // expected-warning {{equality comparison result unused}} \
- // expected-note {{use '=' to turn this equality comparison into an assignment}}
+ // expected-note {{use '=' to turn this equality comparison into an assignment}} \
+ // expected-warning {{comparison of function 'oneT<int>' equal to a null pointer is always false}} \
+ // expected-note {{prefix with the address-of operator to silence this warning}}
}