[cfe-commits] r79791 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaExpr.cpp test/CXX/temp/temp.decls/temp.class.spec/temp.class.spec.mfunc/p1.cpp test/Sema/compare.c
Chris Lattner
sabre at nondot.org
Sat Aug 22 17:03:45 PDT 2009
Author: lattner
Date: Sat Aug 22 19:03:44 2009
New Revision: 79791
URL: http://llvm.org/viewvc/llvm-project?rev=79791&view=rev
Log:
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!
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/CXX/temp/temp.decls/temp.class.spec/temp.class.spec.mfunc/p1.cpp
cfe/trunk/test/Sema/compare.c
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=79791&r1=79790&r2=79791&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sat Aug 22 19:03:44 2009
@@ -1348,6 +1348,8 @@
"%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<
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=79791&r1=79790&r2=79791&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Sat Aug 22 19:03:44 2009
@@ -4358,10 +4358,16 @@
}
}
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 @@
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();
}
Modified: cfe/trunk/test/CXX/temp/temp.decls/temp.class.spec/temp.class.spec.mfunc/p1.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/temp/temp.decls/temp.class.spec/temp.class.spec.mfunc/p1.cpp?rev=79791&r1=79790&r2=79791&view=diff
==============================================================================
--- cfe/trunk/test/CXX/temp/temp.decls/temp.class.spec/temp.class.spec.mfunc/p1.cpp (original)
+++ cfe/trunk/test/CXX/temp/temp.decls/temp.class.spec/temp.class.spec.mfunc/p1.cpp Sat Aug 22 19:03:44 2009
@@ -23,4 +23,4 @@
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; }
Modified: cfe/trunk/test/Sema/compare.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/compare.c?rev=79791&r1=79790&r2=79791&view=diff
==============================================================================
--- cfe/trunk/test/Sema/compare.c (original)
+++ cfe/trunk/test/Sema/compare.c Sat Aug 22 19:03:44 2009
@@ -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 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}}
}
More information about the cfe-commits
mailing list