From 2032fb973bfd926cd47023f15d5361ac5b532bc0 Mon Sep 17 00:00:00 2001 From: Edwin Vane Date: Fri, 15 Mar 2013 20:18:08 +0000 Subject: Don't include outer-most explicit cast in nullptr replacement The outer-most explicit cast is now left alone by the Use-Nullptr transform to maintain the type of the expression and avoid introducing ambiguities. Fixes PR15395. Author: Ariel J Bernal llvm-svn: 177179 --- .../test/cpp11-migrate/UseNullptr/basic.cpp | 55 +++++++++++++++++++--- 1 file changed, 48 insertions(+), 7 deletions(-) (limited to 'clang-tools-extra/test/cpp11-migrate/UseNullptr') diff --git a/clang-tools-extra/test/cpp11-migrate/UseNullptr/basic.cpp b/clang-tools-extra/test/cpp11-migrate/UseNullptr/basic.cpp index de69a1fd3d6..46cc9cf83dc 100644 --- a/clang-tools-extra/test/cpp11-migrate/UseNullptr/basic.cpp +++ b/clang-tools-extra/test/cpp11-migrate/UseNullptr/basic.cpp @@ -69,16 +69,16 @@ template struct Bar { Bar(T *p) : m_p(p) { m_p = static_cast(NULL); - // CHECK: m_p = nullptr; + // CHECK: m_p = static_cast(nullptr); m_p = static_cast(reinterpret_cast((void*)NULL)); - // CHECK: m_p = nullptr; + // CHECK: m_p = static_cast(nullptr); m_p = static_cast(p ? p : static_cast(g_null)); - // CHECK: m_p = static_cast(p ? p : nullptr); + // CHECK: m_p = static_cast(p ? p : static_cast(nullptr)); T *p2 = static_cast(reinterpret_cast((void*)NULL)); - // CHECK: T *p2 = nullptr; + // CHECK: T *p2 = static_cast(nullptr); m_p = NULL; // CHECK: m_p = nullptr; @@ -223,15 +223,56 @@ int *test_nested_parentheses_expression() { void *test_parentheses_explicit_cast() { return(static_cast(0)); - // CHECK: return(nullptr); + // CHECK: return(static_cast(nullptr)); } void *test_parentheses_explicit_cast_sequence1() { return(static_cast(static_cast((void*)NULL))); - // CHECK: return(nullptr); + // CHECK: return(static_cast(nullptr)); } void *test_parentheses_explicit_cast_sequence2() { return(static_cast(reinterpret_cast((float*)int(0.f)))); - // CHECK: return(nullptr); + // CHECK: return(static_cast(nullptr)); +} + +// Test explicit cast expressions resulting in nullptr +struct Bam { + Bam(int *a) {} + Bam(float *a) {} + Bam operator=(int *a) { return Bam(a); } + Bam operator=(float *a) { return Bam(a); } +}; + +void ambiguous_function(int *a) {} +void ambiguous_function(float *a) {} + +void test_explicit_cast_ambiguous1() { + ambiguous_function((int*)0); + // CHECK: ambiguous_function((int*)nullptr); +} + +void test_explicit_cast_ambiguous2() { + ambiguous_function((int*)(0)); + // CHECK: ambiguous_function((int*)nullptr); +} + +void test_explicit_cast_ambiguous3() { + ambiguous_function(static_cast(reinterpret_cast((float*)0))); + // CHECK: ambiguous_function(static_cast(nullptr)); +} + +Bam test_explicit_cast_ambiguous4() { + return(((int*)(0))); + // CHECK: return(((int*)nullptr)); +} + +void test_explicit_cast_ambiguous5() { + // Test for ambiguous overloaded constructors + Bam k((int*)(0)); + // CHECK: Bam k((int*)nullptr); + + // Test for ambiguous overloaded operators + k = (int*)0; + // CHECK: k = (int*)nullptr; } -- cgit v1.2.3