diff options
author | Edwin Vane <edwin.vane@intel.com> | 2013-02-17 16:45:54 +0000 |
---|---|---|
committer | Edwin Vane <edwin.vane@intel.com> | 2013-02-17 16:45:54 +0000 |
commit | 92617fa4bc000c900b1a98018215e3aea0092c00 (patch) | |
tree | ca16359866b461d691b5d643b40bc29636aebc4f /test | |
parent | 81ea1fbaa8327e50fdc208ccb34983c2f82d72c6 (diff) |
Fix -use-nullptr problems with assert()
If a cast expression (NullToPointer) is detected in a function-like macro
parameter, we should use the spelling location instead of the expansion
location. Using SourceManager::getFileLoc() fixes this problem.
Also added testcases for this bug.
Fixes: PR15279
Author: Tareq A Siraj <tareq.a.siraj@intel.com>
Reviewer: klimek
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@175399 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r-- | test/cpp11-migrate/UseNullptr/basic.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/test/cpp11-migrate/UseNullptr/basic.cpp b/test/cpp11-migrate/UseNullptr/basic.cpp index a0d93b13..c9dc404b 100644 --- a/test/cpp11-migrate/UseNullptr/basic.cpp +++ b/test/cpp11-migrate/UseNullptr/basic.cpp @@ -178,3 +178,29 @@ int test_function_return6() { return g_null; // CHECK: return g_null; } + +// Test function-like macros where the parameter to the macro (expression) +// results in a nullptr. +void __dummy_assert_fail() {} + +void test_function_like_macro1() { + // This tests that the CastSequenceVisitor is working properly. +#define my_assert(expr) \ + ((expr) ? static_cast<void>(expr) : __dummy_assert_fail()) + + int *p; + my_assert(p != 0); + // CHECK: my_assert(p != nullptr); +#undef my_assert +} + +void test_function_like_macro2() { + // This tests that the implicit cast is working properly. +#define my_macro(expr) \ + (expr) + + int *p; + my_macro(p != 0); + // CHECK: my_macro(p != nullptr); +#undef my_macro +} |