Skip to content

Commit

Permalink
Merge pull request #168 from Flamefire/clang_asan_fix
Browse files Browse the repository at this point in the history
Workaround Clang 14 ASAN false positive on throwing exceptions
  • Loading branch information
Flamefire committed Jun 6, 2022
2 parents 699bb3b + 23c7493 commit 376479c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ jobs:
- { compiler: clang-6.0, cxxstd: '03,11,14', os: ubuntu-18.04, stdlib: libc++, install: 'clang-6.0 libc++-dev libc++abi-dev' }
- { compiler: clang-12, cxxstd: '03,11,14,17,20', os: ubuntu-20.04, stdlib: libc++, install: 'clang-12 libc++-12-dev libc++abi-12-dev' }
- { name: Clang w/ sanitizers, sanitize: yes,
compiler: clang-14, cxxstd: '03,11,14,17,20', os: ubuntu-22.04, stdlib: libc++, install: 'clang-14 libc++-14-dev libc++abi-14-dev' }
compiler: clang-12, cxxstd: '03,11,14,17,20', os: ubuntu-20.04, stdlib: libc++, install: 'clang-12 libc++-12-dev libc++abi-12-dev' }

# OSX, clang
- { compiler: clang, cxxstd: '03,11,14,17,2a', os: macos-10.15, sanitize: yes }
Expand Down
30 changes: 18 additions & 12 deletions include/boost/boost-ci/boost_ci.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,38 @@

// Just something so we can test dependencies on other Boost libs
#include <boost/config.hpp>
#include <stdexcept>
#ifndef BOOST_NO_CXX11_SMART_PTR
#include <memory>
#endif

#ifdef BOOST_MSVC
#define MSVC_VALUE 1
#else
#define MSVC_VALUE 0
#endif

namespace boost
{
namespace boost_ci
{
#ifdef BOOST_MSVC
#define MSVC_VALUE true
#else
#define MSVC_VALUE false
#endif
class BOOST_SYMBOL_VISIBLE example_error : public std::runtime_error {
public:
example_error() : std::runtime_error("Example error for demonstration") {}
};

// Some function to test
BOOST_NOINLINE int get_answer(const bool isMsvc = MSVC_VALUE)
BOOST_NOINLINE int get_answer(const int isMsvc = MSVC_VALUE)
{
int answer;
// Specifically crafted condition to check for coverage from MSVC and non MSVC builds
if(isMsvc)
{
answer = 21;
} else
{
if(isMsvc == 0)
answer = 42;
}
else if(isMsvc == 1)
answer = 21;
else
throw example_error();

#ifdef BOOST_NO_CXX11_SMART_PTR
return answer;
#else
Expand Down
1 change: 1 addition & 0 deletions test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ int main()
BOOST_TEST_EQ(boost::boost_ci::get_answer(), 42);
}
BOOST_TEST_EQ(map["result"].size(), 1u);
BOOST_TEST_THROWS(boost::boost_ci::get_answer(-1), boost::boost_ci::example_error);
return boost::report_errors();
}

0 comments on commit 376479c

Please sign in to comment.