summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/test/cpp11-migrate/UseNullptr/basic.cpp
diff options
context:
space:
mode:
authorEdwin Vane <edwin.vane@intel.com>2013-02-17 16:45:54 +0000
committerEdwin Vane <edwin.vane@intel.com>2013-02-17 16:45:54 +0000
commit4ad00b46fbb0bfe2530b6cdd8803937166bfa80f (patch)
tree4ed87ff128357e28d7ae702f1b94d68fa7c4fd9b /clang-tools-extra/test/cpp11-migrate/UseNullptr/basic.cpp
parent1cba0a8e0aea9758a066bb8802020ee8f6502b06 (diff)
downloadbcm5719-llvm-4ad00b46fbb0bfe2530b6cdd8803937166bfa80f.tar.gz
bcm5719-llvm-4ad00b46fbb0bfe2530b6cdd8803937166bfa80f.zip
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 llvm-svn: 175399
Diffstat (limited to 'clang-tools-extra/test/cpp11-migrate/UseNullptr/basic.cpp')
-rw-r--r--clang-tools-extra/test/cpp11-migrate/UseNullptr/basic.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/clang-tools-extra/test/cpp11-migrate/UseNullptr/basic.cpp b/clang-tools-extra/test/cpp11-migrate/UseNullptr/basic.cpp
index a0d93b13004..c9dc404b8a3 100644
--- a/clang-tools-extra/test/cpp11-migrate/UseNullptr/basic.cpp
+++ b/clang-tools-extra/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
+}
OpenPOWER on IntegriCloud