Skip to content

Commit

Permalink
fix catch blocks to capture by reference (#8)
Browse files Browse the repository at this point in the history
* fix catch blocks to capture by reference

* add static analyzers

* add suppressions file

* fix cppcheck issues

* more cppcheck fixes

* Automated formatting of files (#9)

Co-authored-by: Philip Top <[email protected]>
Co-authored-by: HELICS-bot <[email protected]>

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: HELICS-bot <[email protected]>
  • Loading branch information
3 people authored Jun 9, 2020
1 parent 0912199 commit d98448f
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 49 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/static-analyzers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Static Analyzers

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
cpplint:
runs-on: ubuntu-latest
container: helics/buildenv:cpplint

steps:
- uses: actions/checkout@v2
- name: Run cpplint
run: cpplint --counting=detailed --recursive gmlc/utilities tests
cppcheck:
runs-on: ubuntu-latest
container: helics/buildenv:cppcheck2

steps:
- uses: actions/checkout@v2
- name: Run cppcheck
run: cppcheck --enable=performance,portability --language=c++ --suppressions-list=config/cppcheck_suppressions.txt --error-exitcode=-4 -i gmlc/extra -i orig_code -i scripts -i config .
2 changes: 2 additions & 0 deletions config/cppcheck_suppressions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#unusedFunction:units/x12_conv.cpp:1024
arrayIndexOutOfBounds:gmlc/utilities/dpcomp.cpp
43 changes: 0 additions & 43 deletions gmlc/utilities/main.c

This file was deleted.

7 changes: 4 additions & 3 deletions gmlc/utilities/string_viewConversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#endif

#include <stdexcept>
#include <string>
#include <vector>

namespace gmlc {
Expand Down Expand Up @@ -140,7 +141,7 @@ namespace utilities {
template<>
inline long double numConv(string_view V)
{
return std::stold(std::string(V.data(),V.length()));
return std::stold(std::string(V.data(), V.length()));
}

// template for numeric conversion returning the position
Expand Down Expand Up @@ -191,7 +192,7 @@ namespace utilities {
try {
return numConv<X>(V);
}
catch (std::invalid_argument) {
catch (const std::invalid_argument&) {
return defValue;
}
}
Expand All @@ -216,7 +217,7 @@ namespace utilities {
}
return res;
}
catch (std::invalid_argument) {
catch (const std::invalid_argument&) {
return defValue;
}
}
Expand Down
4 changes: 2 additions & 2 deletions gmlc/utilities/string_viewDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ All rights reserved. SPDX-License-Identifier: BSD-3-Clause
namespace gmlc {
namespace utilities {
using string_view = std::string_view;
}
} // namespace utilities
} // namespace gmlc
#elif defined(USE_BOOST_STRING_VIEW)
#include "boost/utility/string_view.hpp"
namespace gmlc {
namespace utilities {
using string_view = boost::string_view;
}
} // namespace utilities
} // namespace gmlc
#else
#include <gmlc/extra/string_view.hpp>
Expand Down
2 changes: 1 addition & 1 deletion gmlc/utilities/timeStringOps.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ for example "1.234" or "1032ms"
@throws invalid_argument if the string is not a valid time
*/
template<class timeX>
timeX loadTimeFromString(std::string timeString, time_units defUnit)
timeX loadTimeFromString(const std::string& timeString, time_units defUnit)
{
return timeX(getTimeValue(timeString, defUnit));
}
Expand Down

0 comments on commit d98448f

Please sign in to comment.