Project Euler Problem #10
You need to check for overflow before adding.

for (int i=2; i&lt;=upLimit; i++) {
    if (isPrime[i]) {
        // Check for overflow
        if (std::numeric_limits&lt;decltype(sum)&gt;::max() - sum &lt;= i) {
            std::cerr &lt;&lt; "Overflow" &lt;&lt; std::endl;
            return 1;
        }

        // add to sum
        sum += i;
        …


As int is only guaranteed to hold values up to 32767, you'll find that you should use a long long for sum.