diff options
Diffstat (limited to 'gcc/testsuite/g++.dg/warn/Wnull-conversion-2.C')
-rw-r--r-- | gcc/testsuite/g++.dg/warn/Wnull-conversion-2.C | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/warn/Wnull-conversion-2.C b/gcc/testsuite/g++.dg/warn/Wnull-conversion-2.C new file mode 100644 index 00000000000..92a87d1e76c --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wnull-conversion-2.C @@ -0,0 +1,45 @@ +// { dg-do compile } +// { dg-options "-Wconversion-null" } + +#include <stddef.h> + +class Foo { + public: + template <typename T1, typename T2> + static void Compare(const T1& expected, const T2& actual) { } + + template <typename T1, typename T2> + static void Compare(const T1& expected, T2* actual) { } + +}; + +template<typename T1> +class Foo2 { + public: + Foo2(int x); + template<typename T2> void Bar(T2 y); +}; + +template<typename T3> void func(T3 x) { } + +typedef Foo2<int> MyFooType; + +void func1(long int a) { + MyFooType *foo2 = new MyFooType(NULL); // { dg-warning "passing NULL to" } + foo2->Bar(a); + func(NULL); + func<int>(NULL); // { dg-warning "passing NULL to" } + func<int *>(NULL); +} + +int x = 1; + +main() +{ + int *p = &x; + + Foo::Compare(0, *p); + Foo::Compare<long int, int>(NULL, p); // { dg-warning "passing NULL to" } + Foo::Compare(NULL, p); + func1(NULL); // { dg-warning "passing NULL to" } +} |