Commit a2f62935b35aebe68a5a2f7e729ae4bb8734cfc7

Authored by Jay Berkenbilt
1 parent 3d6615b2

Catch exceptions as const references (fixes #236)

This fix allows qpdf to compile/test cleanly with gcc 8.
examples/pdf-split-pages.cc
... ... @@ -77,7 +77,7 @@ int main(int argc, char* argv[])
77 77 {
78 78 process(whoami, argv[1], argv[2]);
79 79 }
80   - catch (std::exception e)
  80 + catch (std::exception const& e)
81 81 {
82 82 std::cerr << whoami << ": exception: " << e.what() << std::endl;
83 83 return 2;
... ...
libqpdf/MD5.cc
... ... @@ -421,7 +421,7 @@ MD5::checkFileChecksum(char const* const checksum,
421 421 std::string actual_checksum = getFileChecksum(filename, up_to_size);
422 422 result = (checksum == actual_checksum);
423 423 }
424   - catch (std::runtime_error)
  424 + catch (std::runtime_error const&)
425 425 {
426 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 26 result = fn(str);
27 27 worked = (wanted == result);
28 28 }
29   - catch (std::runtime_error)
  29 + catch (std::runtime_error const&)
30 30 {
31 31 threw = true;
32 32 }
... ... @@ -247,7 +247,7 @@ void same_file_test()
247 247 fclose(QUtil::safe_fopen("qutil.out", "r"));
248 248 fclose(QUtil::safe_fopen("other-file", "r"));
249 249 }
250   - catch (std::exception)
  250 + catch (std::exception const&)
251 251 {
252 252 std::cout << "same_file_test expects to have qutil.out and other-file"
253 253 " exist in the current directory\n";
... ...
qpdf/qpdf.cc
... ... @@ -773,7 +773,7 @@ static std::vector&lt;int&gt; 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 778 if (throw_error)
779 779 {
... ... @@ -1372,7 +1372,7 @@ static void parse_rotation_parameter(Options&amp; o, std::string const&amp; parameter)
1372 1372 parse_numrange(range.c_str(), 0, true);
1373 1373 range_valid = true;
1374 1374 }
1375   - catch (std::runtime_error)
  1375 + catch (std::runtime_error const&)
1376 1376 {
1377 1377 // ignore
1378 1378 }
... ...
qpdf/test_driver.cc
... ... @@ -717,7 +717,7 @@ void runtest(int n, char const* filename1, char const* arg2)
717 717 // Do it wrong first...
718 718 pdf.replaceObject(qdict.getObjGen(), qdict);
719 719 }
720   - catch (std::logic_error)
  720 + catch (std::logic_error const&)
721 721 {
722 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 1003 res2.unparseResolved();
1004 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 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 1012 res2.makeDirect();
1013 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 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 1109 pdf.copyForeignObject(pdf.getTrailer().getKey("/QTest"));
1110 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 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 1118 pdf.copyForeignObject(QPDFObjectHandle::newInteger(1));
1119 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 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 1139 w.write();
1140 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 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 1185 QPDFObjectHandle::parse("[1 0 R]", "indirect test");
1186 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 1190 std::cout << "logic error parsing indirect: " << e.what()
1191 1191 << std::endl;
... ... @@ -1195,7 +1195,7 @@ void runtest(int n, char const* filename1, char const* arg2)
1195 1195 QPDFObjectHandle::parse("0 trailing", "trailing test");
1196 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 1200 std::cout << "trailing data: " << e.what()
1201 1201 << std::endl;
... ...