aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-08-23 00:03:44 +0000
committerChris Lattner <sabre@nondot.org>2009-08-23 00:03:44 +0000
commit06c0f5b1bb1623a93a2bc4c345fb3be52a2b22a7 (patch)
tree5cda5a969eec117a4edd666ea5b6c711b224eac9
parentd1a9bac24466831e089c8f330ec9264fb3ace367 (diff)
Eli points out that we really must diagnose "void* > 0" as an extension.
Explicitly add it as an EXTENSION instead of an EXTWARN so that it only comes out with -pedantic. Thanks Eli! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@79791 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Basic/DiagnosticSemaKinds.td2
-rw-r--r--lib/Sema/SemaExpr.cpp27
-rw-r--r--test/CXX/temp/temp.decls/temp.class.spec/temp.class.spec.mfunc/p1.cpp2
-rw-r--r--test/Sema/compare.c6
4 files changed, 26 insertions, 11 deletions
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td
index 0a90af13c7..d0a6cd308f 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1348,6 +1348,8 @@ def err_typecheck_sub_ptr_compatible : Error<
"%0 and %1 are not pointers to compatible types">;
def ext_typecheck_ordered_comparison_of_pointer_integer : ExtWarn<
"ordered comparison between pointer and integer (%0 and %1)">;
+def ext_typecheck_ordered_comparison_of_pointer_and_zero : Extension<
+ "ordered comparison between pointer and zero (%0 and %1) is an extension">;
def ext_typecheck_ordered_comparison_of_function_pointers : ExtWarn<
"ordered comparison of function pointers (%0 and %1)">;
def ext_typecheck_comparison_of_pointer_integer : ExtWarn<
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index f9ec6afc28..5920291225 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -4358,10 +4358,16 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation Loc,
}
}
if (lType->isAnyPointerType() && rType->isIntegerType()) {
- if (!RHSIsNull) {
- unsigned DiagID = isRelational
- ? diag::ext_typecheck_ordered_comparison_of_pointer_integer
- : diag::ext_typecheck_comparison_of_pointer_integer;
+ unsigned DiagID = 0;
+ if (RHSIsNull) {
+ if (isRelational)
+ DiagID = diag::ext_typecheck_ordered_comparison_of_pointer_and_zero;
+ } else if (isRelational)
+ DiagID = diag::ext_typecheck_ordered_comparison_of_pointer_integer;
+ else
+ DiagID = diag::ext_typecheck_comparison_of_pointer_integer;
+
+ if (DiagID) {
Diag(Loc, DiagID)
<< lType << rType << lex->getSourceRange() << rex->getSourceRange();
}
@@ -4369,11 +4375,16 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation Loc,
return ResultTy;
}
if (lType->isIntegerType() && rType->isAnyPointerType()) {
- if (!LHSIsNull) {
- unsigned DiagID = isRelational
- ? diag::ext_typecheck_ordered_comparison_of_pointer_integer
- : diag::ext_typecheck_comparison_of_pointer_integer;
+ unsigned DiagID = 0;
+ if (LHSIsNull) {
+ if (isRelational)
+ DiagID = diag::ext_typecheck_ordered_comparison_of_pointer_and_zero;
+ } else if (isRelational)
+ DiagID = diag::ext_typecheck_ordered_comparison_of_pointer_integer;
+ else
+ DiagID = diag::ext_typecheck_comparison_of_pointer_integer;
+ if (DiagID) {
Diag(Loc, DiagID)
<< lType << rType << lex->getSourceRange() << rex->getSourceRange();
}
diff --git a/test/CXX/temp/temp.decls/temp.class.spec/temp.class.spec.mfunc/p1.cpp b/test/CXX/temp/temp.decls/temp.class.spec/temp.class.spec.mfunc/p1.cpp
index bd9a06de31..b63c56c40f 100644
--- a/test/CXX/temp/temp.decls/temp.class.spec/temp.class.spec.mfunc/p1.cpp
+++ b/test/CXX/temp/temp.decls/temp.class.spec/temp.class.spec.mfunc/p1.cpp
@@ -23,4 +23,4 @@ template<class X> A<X*, 2>::A(X) { value = 0; }
template<class X> A<X*, 2>::~A() { }
-template<class X> A<X*, 2>::operator X*() { return 0; } \ No newline at end of file
+template<class X> A<X*, 2>::operator X*() { return 0; }
diff --git a/test/Sema/compare.c b/test/Sema/compare.c
index 2afaab523b..6b64bac37d 100644
--- a/test/Sema/compare.c
+++ b/test/Sema/compare.c
@@ -5,7 +5,8 @@
int test(char *C) { // nothing here should warn.
return C != ((void*)0);
return C != (void*)0;
- return C != 0;
+ return C != 0;
+ return C != 1; // expected-warning {{comparison between pointer and integer ('char *' and 'int')}}
}
int equal(char *a, const char *b) {
@@ -18,7 +19,8 @@ int arrays(char (*a)[5], char(*b)[10], char(*c)[5]) {
}
int pointers(int *a) {
- return a > 0; // no warning. rdar://7163039
+ return a > 0; // expected-warning {{ordered comparison between pointer and zero ('int *' and 'int') is an extension}}
+ return a > 42; // expected-warning {{ordered comparison between pointer and integer ('int *' and 'int')}}
return a > (void *)0; // expected-warning {{comparison of distinct pointer types}}
}