diff options
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/Sema/warn-null.c | 11 | ||||
-rw-r--r-- | clang/test/SemaTemplate/dependent-expr.cpp | 14 |
2 files changed, 25 insertions, 0 deletions
diff --git a/clang/test/Sema/warn-null.c b/clang/test/Sema/warn-null.c new file mode 100644 index 00000000000..28fb6a5f691 --- /dev/null +++ b/clang/test/Sema/warn-null.c @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 %s -verify + +// PR10837: Warn if a non-pointer-typed expression is folded to a null pointer +int *p = 0; +int *q = '\0'; // expected-warning{{expression which evaluates to zero treated as a null pointer constant}} +int *r = (1 - 1); // expected-warning{{expression which evaluates to zero treated as a null pointer constant}} +void f() { + p = 0; + q = '\0'; // expected-warning{{expression which evaluates to zero treated as a null pointer constant}} + r = 1 - 1; // expected-warning{{expression which evaluates to zero treated as a null pointer constant}} +} diff --git a/clang/test/SemaTemplate/dependent-expr.cpp b/clang/test/SemaTemplate/dependent-expr.cpp index 01ac42ed421..2c26ec53a0a 100644 --- a/clang/test/SemaTemplate/dependent-expr.cpp +++ b/clang/test/SemaTemplate/dependent-expr.cpp @@ -79,3 +79,17 @@ template<typename T> struct CastDependentIntToPointer { return ((void*)(((unsigned long)(x)|0x1ul))); } }; + +// Regression test for crasher in r194540. +namespace PR10837 { + typedef void t(int); + template<typename> struct A { + void f(); + static t g; + }; + t *p; + template<typename T> void A<T>::f() { + p = g; + } + template struct A<int>; +} |