Commit a2f62935b35aebe68a5a2f7e729ae4bb8734cfc7
1 parent
3d6615b2
Catch exceptions as const references (fixes #236)
This fix allows qpdf to compile/test cleanly with gcc 8.
Showing
5 changed files
with
14 additions
and
14 deletions
examples/pdf-split-pages.cc
| @@ -77,7 +77,7 @@ int main(int argc, char* argv[]) | @@ -77,7 +77,7 @@ int main(int argc, char* argv[]) | ||
| 77 | { | 77 | { |
| 78 | process(whoami, argv[1], argv[2]); | 78 | process(whoami, argv[1], argv[2]); |
| 79 | } | 79 | } |
| 80 | - catch (std::exception e) | 80 | + catch (std::exception const& e) |
| 81 | { | 81 | { |
| 82 | std::cerr << whoami << ": exception: " << e.what() << std::endl; | 82 | std::cerr << whoami << ": exception: " << e.what() << std::endl; |
| 83 | return 2; | 83 | return 2; |
libqpdf/MD5.cc
| @@ -421,7 +421,7 @@ MD5::checkFileChecksum(char const* const checksum, | @@ -421,7 +421,7 @@ MD5::checkFileChecksum(char const* const checksum, | ||
| 421 | std::string actual_checksum = getFileChecksum(filename, up_to_size); | 421 | std::string actual_checksum = getFileChecksum(filename, up_to_size); |
| 422 | result = (checksum == actual_checksum); | 422 | result = (checksum == actual_checksum); |
| 423 | } | 423 | } |
| 424 | - catch (std::runtime_error) | 424 | + catch (std::runtime_error const&) |
| 425 | { | 425 | { |
| 426 | // Ignore -- return false | 426 | // Ignore -- return false |
| 427 | } | 427 | } |
libtests/qutil.cc
| @@ -26,7 +26,7 @@ void test_to_number(char const* str, int_T wanted, bool error, | @@ -26,7 +26,7 @@ void test_to_number(char const* str, int_T wanted, bool error, | ||
| 26 | result = fn(str); | 26 | result = fn(str); |
| 27 | worked = (wanted == result); | 27 | worked = (wanted == result); |
| 28 | } | 28 | } |
| 29 | - catch (std::runtime_error) | 29 | + catch (std::runtime_error const&) |
| 30 | { | 30 | { |
| 31 | threw = true; | 31 | threw = true; |
| 32 | } | 32 | } |
| @@ -247,7 +247,7 @@ void same_file_test() | @@ -247,7 +247,7 @@ void same_file_test() | ||
| 247 | fclose(QUtil::safe_fopen("qutil.out", "r")); | 247 | fclose(QUtil::safe_fopen("qutil.out", "r")); |
| 248 | fclose(QUtil::safe_fopen("other-file", "r")); | 248 | fclose(QUtil::safe_fopen("other-file", "r")); |
| 249 | } | 249 | } |
| 250 | - catch (std::exception) | 250 | + catch (std::exception const&) |
| 251 | { | 251 | { |
| 252 | std::cout << "same_file_test expects to have qutil.out and other-file" | 252 | std::cout << "same_file_test expects to have qutil.out and other-file" |
| 253 | " exist in the current directory\n"; | 253 | " exist in the current directory\n"; |
qpdf/qpdf.cc
| @@ -773,7 +773,7 @@ static std::vector<int> parse_numrange(char const* range, int max, | @@ -773,7 +773,7 @@ static std::vector<int> parse_numrange(char const* range, int max, | ||
| 773 | } | 773 | } |
| 774 | } | 774 | } |
| 775 | } | 775 | } |
| 776 | - catch (std::runtime_error e) | 776 | + catch (std::runtime_error const& e) |
| 777 | { | 777 | { |
| 778 | if (throw_error) | 778 | if (throw_error) |
| 779 | { | 779 | { |
| @@ -1372,7 +1372,7 @@ static void parse_rotation_parameter(Options& o, std::string const& parameter) | @@ -1372,7 +1372,7 @@ static void parse_rotation_parameter(Options& o, std::string const& parameter) | ||
| 1372 | parse_numrange(range.c_str(), 0, true); | 1372 | parse_numrange(range.c_str(), 0, true); |
| 1373 | range_valid = true; | 1373 | range_valid = true; |
| 1374 | } | 1374 | } |
| 1375 | - catch (std::runtime_error) | 1375 | + catch (std::runtime_error const&) |
| 1376 | { | 1376 | { |
| 1377 | // ignore | 1377 | // ignore |
| 1378 | } | 1378 | } |
qpdf/test_driver.cc
| @@ -717,7 +717,7 @@ void runtest(int n, char const* filename1, char const* arg2) | @@ -717,7 +717,7 @@ void runtest(int n, char const* filename1, char const* arg2) | ||
| 717 | // Do it wrong first... | 717 | // Do it wrong first... |
| 718 | pdf.replaceObject(qdict.getObjGen(), qdict); | 718 | pdf.replaceObject(qdict.getObjGen(), qdict); |
| 719 | } | 719 | } |
| 720 | - catch (std::logic_error) | 720 | + catch (std::logic_error const&) |
| 721 | { | 721 | { |
| 722 | std::cout << "caught logic error as expected" << std::endl; | 722 | std::cout << "caught logic error as expected" << std::endl; |
| 723 | } | 723 | } |
| @@ -1003,7 +1003,7 @@ void runtest(int n, char const* filename1, char const* arg2) | @@ -1003,7 +1003,7 @@ void runtest(int n, char const* filename1, char const* arg2) | ||
| 1003 | res2.unparseResolved(); | 1003 | res2.unparseResolved(); |
| 1004 | std::cout << "oops -- didn't throw" << std::endl; | 1004 | std::cout << "oops -- didn't throw" << std::endl; |
| 1005 | } | 1005 | } |
| 1006 | - catch (std::logic_error e) | 1006 | + catch (std::logic_error const& e) |
| 1007 | { | 1007 | { |
| 1008 | std::cout << "logic error: " << e.what() << std::endl; | 1008 | std::cout << "logic error: " << e.what() << std::endl; |
| 1009 | } | 1009 | } |
| @@ -1012,7 +1012,7 @@ void runtest(int n, char const* filename1, char const* arg2) | @@ -1012,7 +1012,7 @@ void runtest(int n, char const* filename1, char const* arg2) | ||
| 1012 | res2.makeDirect(); | 1012 | res2.makeDirect(); |
| 1013 | std::cout << "oops -- didn't throw" << std::endl; | 1013 | std::cout << "oops -- didn't throw" << std::endl; |
| 1014 | } | 1014 | } |
| 1015 | - catch (std::logic_error e) | 1015 | + catch (std::logic_error const& e) |
| 1016 | { | 1016 | { |
| 1017 | std::cout << "logic error: " << e.what() << std::endl; | 1017 | std::cout << "logic error: " << e.what() << std::endl; |
| 1018 | } | 1018 | } |
| @@ -1109,7 +1109,7 @@ void runtest(int n, char const* filename1, char const* arg2) | @@ -1109,7 +1109,7 @@ void runtest(int n, char const* filename1, char const* arg2) | ||
| 1109 | pdf.copyForeignObject(pdf.getTrailer().getKey("/QTest")); | 1109 | pdf.copyForeignObject(pdf.getTrailer().getKey("/QTest")); |
| 1110 | std::cout << "oops -- didn't throw" << std::endl; | 1110 | std::cout << "oops -- didn't throw" << std::endl; |
| 1111 | } | 1111 | } |
| 1112 | - catch (std::logic_error e) | 1112 | + catch (std::logic_error const& e) |
| 1113 | { | 1113 | { |
| 1114 | std::cout << "logic error: " << e.what() << std::endl; | 1114 | std::cout << "logic error: " << e.what() << std::endl; |
| 1115 | } | 1115 | } |
| @@ -1118,7 +1118,7 @@ void runtest(int n, char const* filename1, char const* arg2) | @@ -1118,7 +1118,7 @@ void runtest(int n, char const* filename1, char const* arg2) | ||
| 1118 | pdf.copyForeignObject(QPDFObjectHandle::newInteger(1)); | 1118 | pdf.copyForeignObject(QPDFObjectHandle::newInteger(1)); |
| 1119 | std::cout << "oops -- didn't throw" << std::endl; | 1119 | std::cout << "oops -- didn't throw" << std::endl; |
| 1120 | } | 1120 | } |
| 1121 | - catch (std::logic_error e) | 1121 | + catch (std::logic_error const& e) |
| 1122 | { | 1122 | { |
| 1123 | std::cout << "logic error: " << e.what() << std::endl; | 1123 | std::cout << "logic error: " << e.what() << std::endl; |
| 1124 | } | 1124 | } |
| @@ -1139,7 +1139,7 @@ void runtest(int n, char const* filename1, char const* arg2) | @@ -1139,7 +1139,7 @@ void runtest(int n, char const* filename1, char const* arg2) | ||
| 1139 | w.write(); | 1139 | w.write(); |
| 1140 | std::cout << "oops -- didn't throw" << std::endl; | 1140 | std::cout << "oops -- didn't throw" << std::endl; |
| 1141 | } | 1141 | } |
| 1142 | - catch (std::logic_error e) | 1142 | + catch (std::logic_error const& e) |
| 1143 | { | 1143 | { |
| 1144 | std::cout << "logic error: " << e.what() << std::endl; | 1144 | std::cout << "logic error: " << e.what() << std::endl; |
| 1145 | } | 1145 | } |
| @@ -1185,7 +1185,7 @@ void runtest(int n, char const* filename1, char const* arg2) | @@ -1185,7 +1185,7 @@ void runtest(int n, char const* filename1, char const* arg2) | ||
| 1185 | QPDFObjectHandle::parse("[1 0 R]", "indirect test"); | 1185 | QPDFObjectHandle::parse("[1 0 R]", "indirect test"); |
| 1186 | std::cout << "oops -- didn't throw" << std::endl; | 1186 | std::cout << "oops -- didn't throw" << std::endl; |
| 1187 | } | 1187 | } |
| 1188 | - catch (std::logic_error e) | 1188 | + catch (std::logic_error const& e) |
| 1189 | { | 1189 | { |
| 1190 | std::cout << "logic error parsing indirect: " << e.what() | 1190 | std::cout << "logic error parsing indirect: " << e.what() |
| 1191 | << std::endl; | 1191 | << std::endl; |
| @@ -1195,7 +1195,7 @@ void runtest(int n, char const* filename1, char const* arg2) | @@ -1195,7 +1195,7 @@ void runtest(int n, char const* filename1, char const* arg2) | ||
| 1195 | QPDFObjectHandle::parse("0 trailing", "trailing test"); | 1195 | QPDFObjectHandle::parse("0 trailing", "trailing test"); |
| 1196 | std::cout << "oops -- didn't throw" << std::endl; | 1196 | std::cout << "oops -- didn't throw" << std::endl; |
| 1197 | } | 1197 | } |
| 1198 | - catch (std::runtime_error e) | 1198 | + catch (std::runtime_error const& e) |
| 1199 | { | 1199 | { |
| 1200 | std::cout << "trailing data: " << e.what() | 1200 | std::cout << "trailing data: " << e.what() |
| 1201 | << std::endl; | 1201 | << std::endl; |