Skip to content

Instantly share code, notes, and snippets.

@dabrahams
Created September 4, 2009 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dabrahams/181060 to your computer and use it in GitHub Desktop.
Save dabrahams/181060 to your computer and use it in GitHub Desktop.
// Copyright David Abrahams 2009. Distributed under the Boost
// Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
unsigned count;
unsigned zero; // used to prevent dead code elimination and static analysis. see main
struct counter
{
~counter() { ++count; }
};
template <int N>
int f()
#ifdef EXCEPTION_SPEC
throw()
#endif
{
counter x;
return f<N-1>() + zero;
}
template <>
int f<0>()
#ifdef EXCEPTION_SPEC
throw()
#endif
{
if (zero)
{
#ifndef THROW
throw 42;
#endif
}
else
{
#ifdef THROW
throw 42;
#endif
}
return 42+zero;
}
int main(int argc, char* argv[])
{
zero = (argc == 1000000);
for (int i = 0; i < (10000000 / DEPTH); ++i)
{
# ifdef CATCH
try {
# endif
count = f<DEPTH>();
# ifdef CATCH
} catch(...) {}
# endif
}
return count == 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment