[PATCH] D30592: [clang-tidy] Fix diag message for catch-by-value
Florian Gross via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 3 13:52:23 PST 2017
fgross created this revision.
Herald added a subscriber: JDevlieghere.
catch (std::exception ex)
{
}
Was flagged with "catch handler catches a pointer value".
https://reviews.llvm.org/D30592
Files:
clang-tidy/misc/ThrowByValueCatchByReferenceCheck.cpp
Index: clang-tidy/misc/ThrowByValueCatchByReferenceCheck.cpp
===================================================================
--- clang-tidy/misc/ThrowByValueCatchByReferenceCheck.cpp
+++ clang-tidy/misc/ThrowByValueCatchByReferenceCheck.cpp
@@ -131,22 +131,24 @@
void ThrowByValueCatchByReferenceCheck::diagnoseCatchLocations(
const CXXCatchStmt *catchStmt, ASTContext &context) {
- const char *diagMsgCatchReference = "catch handler catches a pointer value; "
- "should throw a non-pointer value and "
- "catch by reference instead";
if (!catchStmt)
return;
auto caughtType = catchStmt->getCaughtType();
if (caughtType.isNull())
return;
auto *varDecl = catchStmt->getExceptionDecl();
if (const auto *PT = caughtType.getCanonicalType()->getAs<PointerType>()) {
+ const char *diagMsgCatchReference = "catch handler catches a pointer value; "
+ "should throw a non-pointer value and "
+ "catch by reference instead";
// We do not diagnose when catching pointer to strings since we also allow
// throwing string literals.
if (!PT->getPointeeType()->isAnyCharacterType())
diag(varDecl->getLocStart(), diagMsgCatchReference);
} else if (!caughtType->isReferenceType()) {
- // If it's not a pointer and not a reference then it must be thrown "by
+ const char *diagMsgCatchReference = "catch handler catches by value; "
+ "should catch by reference instead";
+ // If it's not a pointer and not a reference then it must be caught "by
// value". In this case we should emit a diagnosis message unless the type
// is trivial.
if (!caughtType.isTrivialType(context))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30592.90531.patch
Type: text/x-patch
Size: 1837 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170303/2fa3aef6/attachment.bin>
More information about the cfe-commits
mailing list