Created
September 4, 2009 19:10
-
-
Save dabrahams/181060 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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