Commit 942014df authored by Davis King's avatar Davis King

Added code that will cause the user to get a linker error if they

violate the one definition rule with inconsistent assert enabling.
parent 4d041ccb
......@@ -8,6 +8,17 @@
#include "../platform.h"
#include <iostream>
// The point of this block of code is to cause a link time error that will prevent a user
// from compiling part of their application with DLIB_ASSERTs enabled and part with them
// disabled since doing that would be a violation of C++'s one definition rule.
extern "C"
{
#ifdef ENABLE_ASSERTS
int USER_ERROR__violation_of_one_definition_rule_detected__inconsistent_use_of_DEBUG_or_ENABLE_ASSERTS_preprocessor_directives;
#else
int USER_ERROR__violation_of_one_definition_rule_detected__inconsistent_use_of_DEBUG_or_ENABLE_ASSERTS_preprocessor_directives_;
#endif
}
#ifndef DLIB_THREAD_POOL_TIMEOUT
// default to 30000 milliseconds
......
......@@ -13,9 +13,25 @@
#include "../queue.h"
#include "../set.h"
// The point of this block of code is to cause a link time error that will prevent a user
// from compiling part of their application with DLIB_ASSERTs enabled and part with them
// disabled since doing that would be a violation of C++'s one definition rule.
extern "C"
{
#ifdef ENABLE_ASSERTS
extern int USER_ERROR__violation_of_one_definition_rule_detected__inconsistent_use_of_DEBUG_or_ENABLE_ASSERTS_preprocessor_directives;
inline int dlib_check_consistent_assert_usage() { USER_ERROR__violation_of_one_definition_rule_detected__inconsistent_use_of_DEBUG_or_ENABLE_ASSERTS_preprocessor_directives = 0; return 0; }
#else
extern int USER_ERROR__violation_of_one_definition_rule_detected__inconsistent_use_of_DEBUG_or_ENABLE_ASSERTS_preprocessor_directives_;
inline int dlib_check_consistent_assert_usage() { USER_ERROR__violation_of_one_definition_rule_detected__inconsistent_use_of_DEBUG_or_ENABLE_ASSERTS_preprocessor_directives_ = 0; return 0; }
#endif
const int dlib_check_assert_helper_variable = dlib_check_consistent_assert_usage();
}
namespace dlib
{
// ----------------------------------------------------------------------------------------
namespace threads_kernel_shared
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment