Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix "code will never be executed" under clang + ccache #1540

Merged
merged 1 commit into from
Feb 18, 2019
Merged

fix "code will never be executed" under clang + ccache #1540

merged 1 commit into from
Feb 18, 2019

Conversation

lesurp
Copy link

@lesurp lesurp commented Feb 13, 2019

Description

The issue, for some otherworldly reason, only seems to appear when using ccache, with the -c flag (see relevant issue).

When compiling any test such as:

#define CATCH_CONFIG_MAIN
#include "catch.hpp"

TEST_CASE("foo", "[bar]")
{
    double a = 2.0;
    double b = 10.0;
    CHECK(a * 5.0/3.0  == b / 3.0);
}

Compiling it (with ccache):

ccache /usr/bin/clang++     -Wunreachable-code   -std=gnu++11 -c /absolute/path/test.cpp
/absolute/path/test.cpp:8:161: warning: code will never be executed [-Wunreachable-code]
 } catch(...) { catchAssertionHandler.handleUnexpectedInflightException(); } catchAssertionHandler.complete(); } while( (void)0, false && static_cast<bool>( !!(a * 5.0/3.0 == b / 3.0) ) );
                                                                                                                                                                ^
/absolute/path/test.cpp:8:130: note: silence by adding parentheses to mark code as explicitly dead
 } catch(...) { catchAssertionHandler.handleUnexpectedInflightException(); } catchAssertionHandler.complete(); } while( (void)0, false && static_cast<bool>( !!(a * 5.0/3.0 == b / 3.0) ) );

Why it is worth fixing:

  1. It creates very noisy warnings, and cannot really be avoided because...
  2. CMake always compiles objects separately by default (therefore with the -c flag)
  3. ... and even if it didn't, since we should compile Catch2's main separately, we'd still need to compile the objects separately

@codecov
Copy link

codecov bot commented Feb 13, 2019

Codecov Report

Merging #1540 into master will not change coverage.
The diff coverage is n/a.

@@          Coverage Diff           @@
##           master   #1540   +/-   ##
======================================
  Coverage    80.6%   80.6%           
======================================
  Files         121     121           
  Lines        3386    3386           
======================================
  Hits         2729    2729           
  Misses        657     657

@JoeyGrajciar JoeyGrajciar merged commit 2bd0722 into catchorg:master Feb 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants