aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Sema/SemaChecking.cpp7
-rw-r--r--test/SemaCXX/conversion.cpp12
2 files changed, 17 insertions, 2 deletions
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp
index cd24a4f459..7ab05c41f7 100644
--- a/lib/Sema/SemaChecking.cpp
+++ b/lib/Sema/SemaChecking.cpp
@@ -4075,8 +4075,11 @@ void CheckImplicitConversion(Sema &S, Expr *E, QualType T,
if ((E->isNullPointerConstant(S.Context, Expr::NPC_ValueDependentIsNotNull)
== Expr::NPCK_GNUNull) && Target->isIntegerType()) {
- S.Diag(E->getExprLoc(), diag::warn_impcast_null_pointer_to_integer)
- << T << E->getSourceRange() << clang::SourceRange(CC);
+ SourceLocation Loc = E->getSourceRange().getBegin();
+ if (Loc.isMacroID())
+ Loc = S.SourceMgr.getImmediateExpansionRange(Loc).first;
+ S.Diag(Loc, diag::warn_impcast_null_pointer_to_integer)
+ << T << Loc << clang::SourceRange(CC);
return;
}
diff --git a/test/SemaCXX/conversion.cpp b/test/SemaCXX/conversion.cpp
index 9e0950634d..a64b18721a 100644
--- a/test/SemaCXX/conversion.cpp
+++ b/test/SemaCXX/conversion.cpp
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -Wconversion -verify %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -Wconversion %s 2>&1 | FileCheck %s
#include <stddef.h>
@@ -68,4 +69,15 @@ void test3() {
char ch = NULL; // expected-warning {{implicit conversion of NULL constant to 'char'}}
unsigned char uch = NULL; // expected-warning {{implicit conversion of NULL constant to 'unsigned char'}}
short sh = NULL; // expected-warning {{implicit conversion of NULL constant to 'short'}}
+
+ // Use FileCheck to ensure we don't get any unnecessary macro-expansion notes
+ // (that don't appear as 'real' notes & can't be seen/tested by -verify)
+ // CHECK-NOT: note:
+ // CHECK: note: expanded from macro 'FNULL'
+#define FNULL NULL
+ int a2 = FNULL; // expected-warning {{implicit conversion of NULL constant to 'int'}}
+ // CHECK-NOT: note:
+ // CHECK: note: expanded from macro 'FINIT'
+#define FINIT int a3 = NULL;
+ FINIT // expected-warning {{implicit conversion of NULL constant to 'int'}}
}