[cfe-commits] r85153 - in /cfe/trunk: lib/Sema/SemaExprCXX.cpp test/FixIt/fixit-pmem.cpp
Fariborz Jahanian
fjahanian at apple.com
Mon Oct 26 13:45:27 PDT 2009
Author: fjahanian
Date: Mon Oct 26 15:45:27 2009
New Revision: 85153
URL: http://llvm.org/viewvc/llvm-project?rev=85153&view=rev
Log:
Add 'fixit' hint on mis-use of pointer-to-member
binary operators.
Added:
cfe/trunk/test/FixIt/fixit-pmem.cpp
Modified:
cfe/trunk/lib/Sema/SemaExprCXX.cpp
Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=85153&r1=85152&r2=85153&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Mon Oct 26 15:45:27 2009
@@ -1404,7 +1404,8 @@
LType = Ptr->getPointeeType().getNonReferenceType();
else {
Diag(Loc, diag::err_bad_memptr_lhs)
- << OpSpelling << 1 << LType << lex->getSourceRange();
+ << OpSpelling << 1 << LType
+ << CodeModificationHint::CreateReplacement(SourceRange(Loc), ".*");
return QualType();
}
}
@@ -1417,8 +1418,10 @@
// overkill?
if (!IsDerivedFrom(LType, Class, Paths) ||
Paths.isAmbiguous(Context.getCanonicalType(Class))) {
+ const char *ReplaceStr = isIndirect ? ".*" : "->*";
Diag(Loc, diag::err_bad_memptr_lhs) << OpSpelling
- << (int)isIndirect << lex->getType() << lex->getSourceRange();
+ << (int)isIndirect << lex->getType() <<
+ CodeModificationHint::CreateReplacement(SourceRange(Loc), ReplaceStr);
return QualType();
}
}
Added: cfe/trunk/test/FixIt/fixit-pmem.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/fixit-pmem.cpp?rev=85153&view=auto
==============================================================================
--- cfe/trunk/test/FixIt/fixit-pmem.cpp (added)
+++ cfe/trunk/test/FixIt/fixit-pmem.cpp Mon Oct 26 15:45:27 2009
@@ -0,0 +1,23 @@
+// RUN: clang-cc -fsyntax-only -pedantic -fixit %s -o - | clang-cc -fsyntax-only -pedantic -Werror -x c++ -
+
+/* This is a test of the various code modification hints that are
+ provided as part of warning or extension diagnostics. All of the
+ warnings will be fixed by -fixit, and the resulting file should
+ compile cleanly with -Werror -pedantic. */
+
+struct S {
+ int i;
+};
+
+int foo(int S::* ps, S s, S* p)
+{
+ p.*ps = 1;
+ return s->*ps;
+}
+
+void foo1(int (S::*ps)(), S s, S* p)
+{
+ (p.*ps)();
+ (s->*ps)();
+}
+
More information about the cfe-commits
mailing list