[PATCH] D30592: [clang-tidy] Fix diag message for catch-by-value
This revision was automatically updated to reflect the committed changes. Closed by commit rL298608: [clang-tidy] Fix diag message for catch-by-value (authored by alexfh). Changed prior to commit: https://reviews.llvm.org/D30592?vs=90572=92805#toc Repository: rL LLVM https://reviews.llvm.org/D30592 Files: clang-tools-extra/trunk/clang-tidy/misc/ThrowByValueCatchByReferenceCheck.cpp clang-tools-extra/trunk/test/clang-tidy/misc-throw-by-value-catch-by-reference.cpp Index: clang-tools-extra/trunk/test/clang-tidy/misc-throw-by-value-catch-by-reference.cpp === --- clang-tools-extra/trunk/test/clang-tidy/misc-throw-by-value-catch-by-reference.cpp +++ clang-tools-extra/trunk/test/clang-tidy/misc-throw-by-value-catch-by-reference.cpp @@ -62,7 +62,7 @@ try { testThrowFunc(); } catch (logic_error e) { -// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: catch handler catches a pointer value; should throw a non-pointer value and catch by reference instead [misc-throw-by-value-catch-by-reference] +// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: catch handler catches by value; should catch by reference instead [misc-throw-by-value-catch-by-reference] } } Index: clang-tools-extra/trunk/clang-tidy/misc/ThrowByValueCatchByReferenceCheck.cpp === --- clang-tools-extra/trunk/clang-tidy/misc/ThrowByValueCatchByReferenceCheck.cpp +++ clang-tools-extra/trunk/clang-tidy/misc/ThrowByValueCatchByReferenceCheck.cpp @@ -131,22 +131,24 @@ void ThrowByValueCatchByReferenceCheck::diagnoseCatchLocations( const CXXCatchStmt *catchStmt, ASTContext ) { - 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()) { +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)) Index: clang-tools-extra/trunk/test/clang-tidy/misc-throw-by-value-catch-by-reference.cpp === --- clang-tools-extra/trunk/test/clang-tidy/misc-throw-by-value-catch-by-reference.cpp +++ clang-tools-extra/trunk/test/clang-tidy/misc-throw-by-value-catch-by-reference.cpp @@ -62,7 +62,7 @@ try { testThrowFunc(); } catch (logic_error e) { -// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: catch handler catches a pointer value; should throw a non-pointer value and catch by reference instead [misc-throw-by-value-catch-by-reference] +// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: catch handler catches by value; should catch by reference instead [misc-throw-by-value-catch-by-reference] } } Index: clang-tools-extra/trunk/clang-tidy/misc/ThrowByValueCatchByReferenceCheck.cpp === --- clang-tools-extra/trunk/clang-tidy/misc/ThrowByValueCatchByReferenceCheck.cpp +++ clang-tools-extra/trunk/clang-tidy/misc/ThrowByValueCatchByReferenceCheck.cpp @@ -131,22 +131,24 @@ void ThrowByValueCatchByReferenceCheck::diagnoseCatchLocations( const CXXCatchStmt *catchStmt, ASTContext ) { - 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()) { +const char *diagMsgCatchReference = "catch handler catches a pointer value; " +"should throw a
[PATCH] D30592: [clang-tidy] Fix diag message for catch-by-value
aaron.ballman accepted this revision. aaron.ballman added a comment. This revision is now accepted and ready to land. LGTM, thank you! https://reviews.llvm.org/D30592 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D30592: [clang-tidy] Fix diag message for catch-by-value
fgross updated this revision to Diff 90572. fgross added a comment. Updated test case. https://reviews.llvm.org/D30592 Files: clang-tidy/misc/ThrowByValueCatchByReferenceCheck.cpp test/clang-tidy/misc-throw-by-value-catch-by-reference.cpp Index: test/clang-tidy/misc-throw-by-value-catch-by-reference.cpp === --- test/clang-tidy/misc-throw-by-value-catch-by-reference.cpp +++ test/clang-tidy/misc-throw-by-value-catch-by-reference.cpp @@ -62,7 +62,7 @@ try { testThrowFunc(); } catch (logic_error e) { -// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: catch handler catches a pointer value; should throw a non-pointer value and catch by reference instead [misc-throw-by-value-catch-by-reference] +// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: catch handler catches by value; should catch by reference instead [misc-throw-by-value-catch-by-reference] } } 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 ) { - 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()) { +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)) Index: test/clang-tidy/misc-throw-by-value-catch-by-reference.cpp === --- test/clang-tidy/misc-throw-by-value-catch-by-reference.cpp +++ test/clang-tidy/misc-throw-by-value-catch-by-reference.cpp @@ -62,7 +62,7 @@ try { testThrowFunc(); } catch (logic_error e) { -// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: catch handler catches a pointer value; should throw a non-pointer value and catch by reference instead [misc-throw-by-value-catch-by-reference] +// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: catch handler catches by value; should catch by reference instead [misc-throw-by-value-catch-by-reference] } } 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 ) { - 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()) { +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; " +
[PATCH] D30592: [clang-tidy] Fix diag message for catch-by-value
aaron.ballman requested changes to this revision. aaron.ballman added a comment. This revision now requires changes to proceed. This change is missing test cases. https://reviews.llvm.org/D30592 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D30592: [clang-tidy] Fix diag message for catch-by-value
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 ) { - 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()) { +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)) 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 ) { - 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()) { +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)) ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits