-
-
Notifications
You must be signed in to change notification settings - Fork 462
Debug assert #1175
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
Debug assert #1175
Changes from 3 commits
4f2c6ac
6fa4fad
1ba8480
cab3bda
eba6eda
6a1f790
e0e6bde
e02a685
97b3ed4
80f4814
07dfe30
d6adf29
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -364,6 +364,16 @@ namespace etl | |
#endif | ||
#endif | ||
|
||
#if ETL_IS_DEBUG_BUILD | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there should be other macros that make There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I filled out the rest of the asserts from the |
||
#if ETL_USING_EXCEPTIONS | ||
#define ETL_DEBUG_ASSERT(b, e) {if (!(b)) ETL_UNLIKELY {throw((e));}} // If the condition fails, throws an exception. | ||
#else | ||
#define ETL_DEBUG_ASSERT(b, e) assert((b)) // If the condition fails, asserts. | ||
#endif | ||
#else | ||
#define ETL_DEBUG_ASSERT(b, e) // Does nothing. | ||
#endif | ||
|
||
#if defined(ETL_VERBOSE_ERRORS) | ||
#define ETL_ERROR(e) (e(__FILE__, __LINE__)) // Make an exception with the file name and line number. | ||
#define ETL_ERROR_WITH_VALUE(e, v) (e(__FILE__, __LINE__, (v))) // Make an exception with the file name, line number and value. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,6 +134,9 @@ namespace | |
{ | ||
CHECK_EQUAL(data[i], compare_data[i]); | ||
} | ||
|
||
//ETL_DEBUG and ETL_THROW_EXCEPTIONS are defined | ||
CHECK_THROW({ int d = data[data.size()]; (void)d; }, etl::array_out_of_range); | ||
} | ||
Comment on lines
+138
to
140
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gate the out-of-bounds [] checks behind the same flags used by ETL_DEBUG_ASSERT. Unconditionally requiring a throw will fail in release or non-exception builds. Guard the checks so they only run when ETL_IS_DEBUG_BUILD && ETL_USING_EXCEPTIONS (or ETL_DEBUG_USING_EXCEPTIONS if adopted). - //ETL_DEBUG and ETL_THROW_EXCEPTIONS are defined
- CHECK_THROW({ int d = data[data.size()]; (void)d; }, etl::array_out_of_range);
+ // Only active when debug + exceptions route is enabled for ETL_DEBUG_ASSERT
+#if ETL_IS_DEBUG_BUILD && ETL_USING_EXCEPTIONS
+ CHECK_THROW({ int d = data[data.size()]; (void)d; }, etl::array_out_of_range);
+#endif 🤖 Prompt for AI Agents
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this applies because there are many tests that that rely on exceptions and debug build already. Basically most tests already rely on these build options. |
||
|
||
//************************************************************************* | ||
|
@@ -145,6 +148,9 @@ namespace | |
{ | ||
CHECK_EQUAL(data[i], compare_data[i]); | ||
} | ||
|
||
//ETL_DEBUG and ETL_THROW_EXCEPTIONS are defined | ||
CHECK_THROW({ int d = data[data.size()]; (void)d; }, etl::array_out_of_range); | ||
} | ||
|
||
//************************************************************************* | ||
|
@@ -443,6 +449,10 @@ namespace | |
CHECK_EQUAL(data[9], *result); | ||
isEqual = std::equal(data.begin(), data.end(), std::begin(check3)); | ||
CHECK(isEqual); | ||
|
||
// Insert out of range | ||
//ETL_DEBUG and ETL_THROW_EXCEPTIONS are defined | ||
CHECK_THROW({ result = data.insert_at(data.size(), 99); }, etl::array_out_of_range); | ||
} | ||
|
||
//************************************************************************* | ||
|
@@ -493,6 +503,10 @@ namespace | |
CHECK_EQUAL(data[4], *result); | ||
isEqual = std::equal(data.begin(), data.end(), std::begin(check5)); | ||
CHECK(isEqual); | ||
|
||
// Insert out of range | ||
//ETL_DEBUG and ETL_THROW_EXCEPTIONS are defined | ||
CHECK_THROW({ result = data.insert_at(data.size(), &source2[0], &source2[13]); }, etl::array_out_of_range); | ||
} | ||
|
||
//************************************************************************* | ||
|
@@ -547,6 +561,10 @@ namespace | |
CHECK_EQUAL(data[9], *result); | ||
isEqual = std::equal(data.begin(), data.end(), std::begin(check3b)); | ||
CHECK(isEqual); | ||
|
||
// Erase out of range | ||
//ETL_DEBUG and ETL_THROW_EXCEPTIONS are defined | ||
CHECK_THROW({ result = data.erase_at(data.size()); }, etl::array_out_of_range); | ||
} | ||
|
||
//************************************************************************* | ||
|
@@ -601,6 +619,13 @@ namespace | |
CHECK_EQUAL(data[5], *result); | ||
isEqual = std::equal(data.begin(), data.end(), std::begin(check3b)); | ||
CHECK(isEqual); | ||
|
||
//ETL_DEBUG and ETL_THROW_EXCEPTIONS are defined | ||
// Erase indexes are equal | ||
CHECK_THROW({ result = data.erase_range(5, 5, 99); }, etl::array_out_of_range); | ||
|
||
// Erase out of range | ||
CHECK_THROW({ result = data.erase_range(5, data.size() + 1, 99); }, etl::array_out_of_range); | ||
} | ||
|
||
//************************************************************************* | ||
|
Uh oh!
There was an error while loading. Please reload this page.