Skip to content

Commit

Permalink
Add clang compiler flag. (see catchorg#2094)
Browse files Browse the repository at this point in the history
  • Loading branch information
HoseynHeydari committed Apr 14, 2022
1 parent bd0ee6a commit c665fd7
Show file tree
Hide file tree
Showing 25 changed files with 80 additions and 49 deletions.
4 changes: 3 additions & 1 deletion examples/231-Cfg-OutputStreams.cpp
Expand Up @@ -10,6 +10,8 @@
#include <sstream>
#include <cstdio>

#include <catch2/internal/catch_compiler_capabilities.hpp>

class out_buff : public std::stringbuf {
std::FILE* m_stream;
public:
Expand All @@ -31,7 +33,7 @@ class out_buff : public std::stringbuf {

out_buff::~out_buff() { pubsync(); }

#if defined(__clang__)
#if defined(CATCH_COMPILER_CLANG)
#pragma clang diagnostic ignored "-Wexit-time-destructors" // static variables in cout/cerr/clog
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/catch2/benchmark/catch_optimizer.hpp
Expand Up @@ -21,7 +21,7 @@

namespace Catch {
namespace Benchmark {
#if defined(CATCH_COMPILER_GCC) || defined(__clang__)
#if defined(CATCH_COMPILER_GCC) || defined(CATCH_COMPILER_CLANG)
template <typename T>
inline void keep_memory(T* p) {
asm volatile("" : : "g"(p) : "memory");
Expand Down
5 changes: 3 additions & 2 deletions src/catch2/benchmark/detail/catch_estimate_clock.hpp
Expand Up @@ -16,6 +16,7 @@
#include <catch2/benchmark/detail/catch_measure.hpp>
#include <catch2/benchmark/detail/catch_run_for_at_least.hpp>
#include <catch2/benchmark/catch_clock.hpp>
#include <catch2/internal/catch_compiler_capabilities.hpp>
#include <catch2/internal/catch_unique_ptr.hpp>

#include <algorithm>
Expand Down Expand Up @@ -95,12 +96,12 @@ namespace Catch {

template <typename Clock>
Environment<FloatDuration<Clock>> measure_environment() {
#if defined(__clang__)
#if defined(CATCH_COMPILER_CLANG)
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wexit-time-destructors"
#endif
static Catch::Detail::unique_ptr<Environment<FloatDuration<Clock>>> env;
#if defined(__clang__)
#if defined(CATCH_COMPILER_CLANG)
# pragma clang diagnostic pop
#endif
if (env) {
Expand Down
5 changes: 3 additions & 2 deletions src/catch2/catch_test_case_info.hpp
Expand Up @@ -8,6 +8,7 @@
#ifndef CATCH_TEST_CASE_INFO_HPP_INCLUDED
#define CATCH_TEST_CASE_INFO_HPP_INCLUDED

#include <catch2/internal/catch_compiler_capabilities.hpp>
#include <catch2/internal/catch_source_line_info.hpp>
#include <catch2/internal/catch_noncopyable.hpp>
#include <catch2/internal/catch_stringref.hpp>
Expand All @@ -18,7 +19,7 @@
#include <string>
#include <vector>

#ifdef __clang__
#ifdef CATCH_COMPILER_CLANG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wpadded"
#endif
Expand Down Expand Up @@ -123,7 +124,7 @@ namespace Catch {
SourceLineInfo const& lineInfo );
}

#ifdef __clang__
#ifdef CATCH_COMPILER_CLANG
#pragma clang diagnostic pop
#endif

Expand Down
6 changes: 4 additions & 2 deletions src/catch2/catch_test_spec.hpp
Expand Up @@ -8,7 +8,9 @@
#ifndef CATCH_TEST_SPEC_HPP_INCLUDED
#define CATCH_TEST_SPEC_HPP_INCLUDED

#ifdef __clang__
#include <catch2/internal/catch_compiler_capabilities.hpp>

#ifdef CATCH_COMPILER_CLANG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wpadded"
#endif
Expand Down Expand Up @@ -81,7 +83,7 @@ namespace Catch {
};
}

#ifdef __clang__
#ifdef CATCH_COMPILER_CLANG
#pragma clang diagnostic pop
#endif

Expand Down
5 changes: 3 additions & 2 deletions src/catch2/internal/catch_clara.hpp
Expand Up @@ -8,7 +8,7 @@
#ifndef CATCH_CLARA_HPP_INCLUDED
#define CATCH_CLARA_HPP_INCLUDED

#if defined( __clang__ )
#if defined( CATCH_COMPILER_CLANG )
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wweak-vtables"
# pragma clang diagnostic ignored "-Wshadow"
Expand All @@ -29,6 +29,7 @@
# endif
#endif

#include <catch2/internal/catch_compiler_capabilities.hpp>
#include <catch2/internal/catch_move_and_forward.hpp>
#include <catch2/internal/catch_noncopyable.hpp>
#include <catch2/internal/catch_void_type.hpp>
Expand Down Expand Up @@ -698,7 +699,7 @@ namespace Catch {
} // namespace Clara
} // namespace Catch

#if defined( __clang__ )
#if defined( CATCH_COMPILER_CLANG )
# pragma clang diagnostic pop
#endif

Expand Down
9 changes: 7 additions & 2 deletions src/catch2/internal/catch_compiler_capabilities.hpp
Expand Up @@ -24,13 +24,18 @@
// Many features, at point of detection, define an _INTERNAL_ macro, so they
// can be combined, en-mass, with the _NO_ forms later.

#include <catch2/internal/catch_compiler_capabilities.hpp>
#include <catch2/internal/catch_platform.hpp>
#include <catch2/catch_user_config.hpp>

#if defined(__GNUC__) && !defined(__clang__) && !defined(__ICC) && !defined(__CUDACC__) && !defined(__LCC__)
#define CATCH_COMPILER_GCC
#endif

#if defined(__clang__) && !defined(_MSC_VER)
#define CATCH_COMPILER_CLANG
#endif

#ifdef __cplusplus

# if (__cplusplus >= 201402L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L)
Expand Down Expand Up @@ -61,7 +66,7 @@

#endif

#if defined(__clang__) && !defined(_MSC_VER)
#if defined(CATCH_COMPILER_CLANG)

# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic push" )
# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic pop" )
Expand Down Expand Up @@ -103,7 +108,7 @@
# define CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
_Pragma( "clang diagnostic ignored \"-Wunused-template\"" )

#endif // __clang__
#endif // CATCH_COMPILER_CLANG


////////////////////////////////////////////////////////////////////////////////
Expand Down
5 changes: 3 additions & 2 deletions src/catch2/internal/catch_console_colour.cpp
Expand Up @@ -5,12 +5,13 @@
// https://www.boost.org/LICENSE_1_0.txt)

// SPDX-License-Identifier: BSL-1.0
#if defined(__clang__)
#if defined(CATCH_COMPILER_CLANG)
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wexit-time-destructors"
#endif


#include <catch2/internal/catch_compiler_capabilities.hpp>
#include <catch2/internal/catch_console_colour.hpp>
#include <catch2/internal/catch_enforce.hpp>
#include <catch2/internal/catch_errno_guard.hpp>
Expand Down Expand Up @@ -277,7 +278,7 @@ namespace Catch {

} // end namespace Catch

#if defined(__clang__)
#if defined(CATCH_COMPILER_CLANG)
# pragma clang diagnostic pop
#endif

5 changes: 3 additions & 2 deletions src/catch2/internal/catch_decomposer.hpp
Expand Up @@ -9,6 +9,7 @@
#define CATCH_DECOMPOSER_HPP_INCLUDED

#include <catch2/catch_tostring.hpp>
#include <catch2/internal/catch_compiler_capabilities.hpp>
#include <catch2/internal/catch_stringref.hpp>
#include <catch2/internal/catch_meta.hpp>

Expand All @@ -23,7 +24,7 @@
#pragma warning(disable:4800) // Forcing result to true or false
#endif

#ifdef __clang__
#ifdef CATCH_COMPILER_CLANG
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wsign-compare"
#elif defined CATCH_COMPILER_GCC
Expand Down Expand Up @@ -259,7 +260,7 @@ namespace Catch {
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#ifdef __clang__
#ifdef CATCH_COMPILER_CLANG
# pragma clang diagnostic pop
#elif defined CATCH_COMPILER_GCC
# pragma GCC diagnostic pop
Expand Down
5 changes: 3 additions & 2 deletions src/catch2/internal/catch_test_case_tracker.cpp
Expand Up @@ -7,14 +7,15 @@
// SPDX-License-Identifier: BSL-1.0
#include <catch2/internal/catch_test_case_tracker.hpp>

#include <catch2/internal/catch_compiler_capabilities.hpp>
#include <catch2/internal/catch_enforce.hpp>
#include <catch2/internal/catch_string_manip.hpp>
#include <catch2/internal/catch_move_and_forward.hpp>

#include <algorithm>
#include <cassert>

#if defined(__clang__)
#if defined(CATCH_COMPILER_CLANG)
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wexit-time-destructors"
#endif
Expand Down Expand Up @@ -245,6 +246,6 @@ namespace TestCaseTracking {

} // namespace Catch

#if defined(__clang__)
#if defined(CATCH_COMPILER_CLANG)
# pragma clang diagnostic pop
#endif
5 changes: 3 additions & 2 deletions src/catch2/internal/catch_test_spec_parser.hpp
Expand Up @@ -8,11 +8,12 @@
#ifndef CATCH_TEST_SPEC_PARSER_HPP_INCLUDED
#define CATCH_TEST_SPEC_PARSER_HPP_INCLUDED

#ifdef __clang__
#ifdef CATCH_COMPILER_CLANG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wpadded"
#endif

#include <catch2/internal/catch_compiler_capabilities.hpp>
#include <catch2/catch_test_spec.hpp>

#include <vector>
Expand Down Expand Up @@ -75,7 +76,7 @@ namespace Catch {

} // namespace Catch

#ifdef __clang__
#ifdef CATCH_COMPILER_CLANG
#pragma clang diagnostic pop
#endif

Expand Down
5 changes: 3 additions & 2 deletions src/catch2/matchers/catch_matchers_floating_point.cpp
Expand Up @@ -6,6 +6,7 @@

// SPDX-License-Identifier: BSL-1.0
#include <catch2/matchers/catch_matchers_floating_point.hpp>
#include <catch2/internal/catch_compiler_capabilities.hpp>
#include <catch2/internal/catch_enforce.hpp>
#include <catch2/internal/catch_polyfills.hpp>
#include <catch2/internal/catch_to_string.hpp>
Expand Down Expand Up @@ -115,7 +116,7 @@ namespace Detail {
"IEEE-754 compatible floating point representation" );
}

#if defined(__clang__)
#if defined(CATCH_COMPILER_CLANG)
#pragma clang diagnostic push
// Clang <3.5 reports on the default branch in the switch below
#pragma clang diagnostic ignored "-Wunreachable-code"
Expand All @@ -132,7 +133,7 @@ namespace Detail {
}
}

#if defined(__clang__)
#if defined(CATCH_COMPILER_CLANG)
#pragma clang diagnostic pop
#endif

Expand Down
5 changes: 3 additions & 2 deletions src/catch2/reporters/catch_reporter_console.cpp
Expand Up @@ -9,6 +9,7 @@

#include <catch2/interfaces/catch_interfaces_config.hpp>
#include <catch2/catch_test_spec.hpp>
#include <catch2/internal/catch_compiler_capabilities.hpp>
#include <catch2/internal/catch_console_colour.hpp>
#include <catch2/internal/catch_string_manip.hpp>
#include <catch2/catch_version.hpp>
Expand All @@ -28,7 +29,7 @@
// Note that 4062 (not all labels are handled and default is missing) is enabled
#endif

#if defined(__clang__)
#if defined(CATCH_COMPILER_CLANG)
# pragma clang diagnostic push
// For simplicity, benchmarking-only helpers are always enabled
# pragma clang diagnostic ignored "-Wunused-function"
Expand Down Expand Up @@ -714,6 +715,6 @@ void ConsoleReporter::printTestFilters() {
#pragma warning(pop)
#endif

#if defined(__clang__)
#if defined(CATCH_COMPILER_CLANG)
# pragma clang diagnostic pop
#endif
5 changes: 3 additions & 2 deletions src/catch2/reporters/catch_reporter_teamcity.hpp
Expand Up @@ -8,12 +8,13 @@
#ifndef CATCH_REPORTER_TEAMCITY_HPP_INCLUDED
#define CATCH_REPORTER_TEAMCITY_HPP_INCLUDED

#include <catch2/internal/catch_compiler_capabilities.hpp>
#include <catch2/reporters/catch_reporter_streaming_base.hpp>
#include <catch2/catch_timer.hpp>

#include <cstring>

#ifdef __clang__
#ifdef CATCH_COMPILER_CLANG
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wpadded"
#endif
Expand Down Expand Up @@ -59,7 +60,7 @@ namespace Catch {

} // end namespace Catch

#ifdef __clang__
#ifdef CATCH_COMPILER_CLANG
# pragma clang diagnostic pop
#endif

Expand Down
7 changes: 4 additions & 3 deletions tests/ExtraTests/X02-DisabledMacros.cpp
Expand Up @@ -14,6 +14,7 @@

#include <catch2/catch_test_macros.hpp>
#include <catch2/benchmark/catch_benchmark.hpp>
#include <catch2/internal/catch_compiler_capabilities.hpp>
#include <catch2/matchers/catch_matchers.hpp>
#include <catch2/matchers/catch_matchers_predicate.hpp>

Expand All @@ -28,15 +29,15 @@ struct foo {
}
};

#if defined(__clang__)
#if defined(CATCH_COMPILER_CLANG)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wglobal-constructors"
#endif
// Construct foo, but `foo::print` should not be run
foo f;


#if defined(__clang__)
#if defined(CATCH_COMPILER_CLANG)
// The test is unused since the registration is disabled
#pragma clang diagnostic ignored "-Wunused-function"
#endif
Expand All @@ -60,6 +61,6 @@ TEST_CASE( "Disabled Macros" ) {
BENCHMARK( "Disabled benchmark" ) { REQUIRE( 1 == 2 ); };
}

#if defined(__clang__)
#if defined(CATCH_COMPILER_CLANG)
#pragma clang diagnostic pop
#endif
7 changes: 4 additions & 3 deletions tests/SelfTest/TestRegistrations.cpp
Expand Up @@ -7,17 +7,18 @@
// SPDX-License-Identifier: BSL-1.0

#include <catch2/catch_tag_alias_autoregistrar.hpp>
#include <catch2/reporters/catch_reporter_event_listener.hpp>
#include <catch2/internal/catch_enforce.hpp>
#include <catch2/catch_test_case_info.hpp>
#include <catch2/internal/catch_compiler_capabilities.hpp>
#include <catch2/internal/catch_enforce.hpp>
#include <catch2/reporters/catch_reporter_event_listener.hpp>
#include <catch2/reporters/catch_reporter_registrars.hpp>


// Some example tag aliases
CATCH_REGISTER_TAG_ALIAS("[@nhf]", "[failing]~[.]")
CATCH_REGISTER_TAG_ALIAS("[@tricky]", "[tricky]~[.]")

#ifdef __clang__
#ifdef CATCH_COMPILER_CLANG
# pragma clang diagnostic ignored "-Wpadded"
# pragma clang diagnostic ignored "-Wweak-vtables"
# pragma clang diagnostic ignored "-Wc++98-compat"
Expand Down

0 comments on commit c665fd7

Please sign in to comment.