Files
pilotclient/src/blackmisc/verify.h
Mathew Sutcliffe c790e344ac BLACK_AUDIT macro for paranoid checks on data consistency
Summary:
Triggers a breakpoint when the debugger is attached to a debug build. Otherwise, logs a warning.

Related: T101

Reviewers: kbasan, rwinklmeier

Reviewed By: kbasan

Subscribers: jenkins

Tags: #swift_pilot_client

Differential Revision: https://dev.swift-project.org/D35
2017-09-24 19:49:35 +01:00

57 lines
2.0 KiB
C++

/* Copyright (C) 2015
* swift project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
//! \file
#ifndef BLACKMISC_VERIFY_H
#define BLACKMISC_VERIFY_H
#include "blackmisc/blackmiscexport.h"
//! \cond
#ifdef Q_CC_MSVC
#define BLACK_NO_INLINE __declspec(noinline)
#else
#define BLACK_NO_INLINE __attribute__((noinline))
#endif
//! \endcond
namespace BlackMisc
{
namespace Private
{
//! \private Do nothing.
inline void noop() {}
//! \private Called by BLACK_VERIFY when the condition is false.
BLACKMISC_EXPORT BLACK_NO_INLINE void failedVerify(const char *condition, const char *filename, int line, const char *context, const char *message, bool audit);
}
}
/*!
* A weaker kind of assert. Still indicates a programmer mistake, but one which is recoverable.
* In debug builds, triggers a debugger breakpoint. In release builds, generates a warning.
*/
//! @{
#define BLACK_VERIFY_X(COND, WHERE, WHAT) ((COND) ? BlackMisc::Private::noop() : BlackMisc::Private::failedVerify(#COND, __FILE__, __LINE__, WHERE, WHAT, false))
#define BLACK_VERIFY(COND) BLACK_VERIFY_X(COND, nullptr, nullptr)
//! @}
/*!
* A weaker kind of verify. Indicative of a serious but recoverable problem originating in an external data source.
* In debug builds under debugging, triggers a debugger breakpoint. Otherwise generates a warning.
* Not a substitute for proper validation. A failed audit in production is suggestive of insufficient validation.
*/
//! @{
#define BLACK_AUDIT_X(COND, WHERE, WHAT) ((COND) ? BlackMisc::Private::noop() : BlackMisc::Private::failedVerify(#COND, __FILE__, __LINE__, WHERE, WHAT, true))
#define BLACK_AUDIT(COND) BLACK_AUDIT_X(COND, nullptr, nullptr)
//! @}
#endif