From 72cccaf687cb142cff312ddda830f2b088cb3cdf Mon Sep 17 00:00:00 2001 From: Jason Lokerson Date: Tue, 19 Aug 2014 10:47:10 -0700 Subject: [PATCH] Adding more descriptive static assertions --- autowiring/has_autofilter.h | 22 ++++++++++++++++------ src/autowiring/test/AutoFilterTest.cpp | 1 - 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/autowiring/has_autofilter.h b/autowiring/has_autofilter.h index 000bf4517..67210a290 100644 --- a/autowiring/has_autofilter.h +++ b/autowiring/has_autofilter.h @@ -10,13 +10,15 @@ template struct has_valid_autofilter { // Evaluates to false for W::AutoFilter(void), else to true. - static const bool value = Decompose::N != 0; + static const int N = Decompose::N; + static const bool value = Decompose::N != 0; }; // Specialization pertains only when W has no AutoFilter method. template struct has_valid_autofilter { - static const bool value = false; + static const int N = -1; + static const bool value = false; }; //=========================================================== @@ -43,8 +45,11 @@ struct has_unambiguous_autofilter template static std::true_type select(unnamed_constant*); + // Conveninece typedef used externally: + typedef has_valid_autofilter(nullptr))> has_valid; + // Evaluates to true only if T includes a unique AutoFilter method with at least one argument. - static const bool value = has_valid_autofilter(nullptr))>::value; + static const bool value = has_valid::value; }; class AutoPacket; @@ -66,10 +71,15 @@ struct has_autofilter { static const bool value = has_unambiguous_autofilter::value; // This class has at least one AutoFilter method - struct detect_ambiguous_autofilter : T, test_valid_autofilter {}; + struct detect_ambiguous_autofilter: T, test_valid_autofilter {}; + + // Validate the case most likely to have problems + static_assert(has_unambiguous_autofilter::has_valid::N != 0, "Cannot define AutoFilter(void), your AutoFilter routine must take at least one argument"); // Ensures a compiler error when the identification of T::AutoFilter is ambiguous. // This cannot be in has_unambiguous_autofilter, since that would be recursive. - static_assert(value || has_unambiguous_autofilter::value, - "Cannot define more than 1 AutoFilter method. Cannot define AutoFilter(void)"); + static_assert( + value || has_unambiguous_autofilter::value, + "Cannot define more than one AutoFilter method and all AutoFilter methods must be public" + ); }; diff --git a/src/autowiring/test/AutoFilterTest.cpp b/src/autowiring/test/AutoFilterTest.cpp index e2d724eb4..1a12ce830 100644 --- a/src/autowiring/test/AutoFilterTest.cpp +++ b/src/autowiring/test/AutoFilterTest.cpp @@ -469,7 +469,6 @@ TEST_F(AutoFilterTest, VerifyAntiDecorate) { /// template struct good_autofilter { - // Evaluates to false when T does not include an AutoFilter method with at least one argument. static const bool value = has_unambiguous_autofilter::value;