-
Notifications
You must be signed in to change notification settings - Fork 392
Add new unit test for runtime exceptions #2505
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
Merged
+112
−2
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| /** | ||
| * Test runtime behavior when throwing a plain C++ pointer in recursion | ||
| */ | ||
|
|
||
| #include "test_config.h" | ||
| #include <cstdio> | ||
| #include <vector> | ||
| #include <memory> | ||
|
|
||
| namespace DynamicAny { | ||
| struct DynAny { virtual ~DynAny() = default; }; | ||
| struct DynValue : virtual DynAny {}; | ||
| struct DynValueCommon : virtual DynAny {}; | ||
| } | ||
|
|
||
| struct TAO_DynCommon : virtual DynamicAny::DynAny { | ||
| virtual ~TAO_DynCommon() | ||
| { | ||
| ACE_DEBUG ((LM_DEBUG, ACE_TEXT("~TAO_DynCommon %@\n"), this)); | ||
| } | ||
| }; | ||
| struct TAO_DynAny_i : virtual TAO_DynCommon, virtual DynamicAny::DynAny { | ||
| virtual ~TAO_DynAny_i() { ACE_DEBUG ((LM_DEBUG, ACE_TEXT("~TAO_DynAny_i %@\n"), this)); } | ||
| }; | ||
| struct TAO_DynValueCommon_i : virtual TAO_DynAny_i, virtual DynamicAny::DynValueCommon { | ||
| virtual ~TAO_DynValueCommon_i() { ACE_DEBUG ((LM_DEBUG, ACE_TEXT("~TAO_DynValueCommon_i %@\n"), this)); } | ||
| }; | ||
| // ============================================================ | ||
| // CreateDynAnyUtils<T> | ||
| // ============================================================ | ||
| template<typename DA_IMPL> | ||
| struct CreateDynAnyUtils { | ||
| static DA_IMPL* create(bool trigger, int depth = 0) { | ||
| ACE_DEBUG ((LM_DEBUG, ACE_TEXT("[Create depth=%d] new DA_IMPL\n"), depth)); | ||
| DA_IMPL* p = new DA_IMPL(); | ||
| std::unique_ptr<DA_IMPL> guard(p); | ||
| try { | ||
| p->from_inputCDR(trigger, depth); | ||
| } | ||
| catch (DA_IMPL* original) { | ||
| ACE_DEBUG ((LM_DEBUG, ACE_TEXT("!!! CAUGHT pointer %@ at depth %d (destroying blank %@) !!!\n"), | ||
| original, depth, p)); | ||
| return original; | ||
| } | ||
| return guard.release(); | ||
| } | ||
| }; | ||
| // ============================================================ | ||
| // TAO_DynValue_i | ||
| // ============================================================ | ||
| struct TAO_DynValue_i : virtual DynamicAny::DynValue, virtual TAO_DynValueCommon_i { | ||
| TAO_DynValue_i() { ACE_DEBUG ((LM_DEBUG, ACE_TEXT("TAO_DynValue_i ctor %@\n"), this)); } | ||
| ~TAO_DynValue_i() override { ACE_DEBUG ((LM_DEBUG, ACE_TEXT("~TAO_DynValue_i dtor %@\n"), this)); } | ||
| static TAO_DynValue_i* cached ; | ||
| std::vector<void*> da_members_; | ||
| void from_inputCDR(bool trigger_indirection, int depth) { | ||
| ACE_DEBUG ((LM_DEBUG, ACE_TEXT(" from_inputCDR depth=%d this=%@\n"), depth, this)); | ||
| // Simulates deep recursion of ACE_TAO (exactly like in the real DynValue_i) | ||
| if (depth < 3) { | ||
| ACE_DEBUG ((LM_DEBUG, ACE_TEXT(" Creating nested member at depth %d\n"), depth + 1)); | ||
| try { | ||
| auto* member = CreateDynAnyUtils<TAO_DynValue_i>::create(trigger_indirection, depth + 1); | ||
| da_members_.push_back(member); | ||
| } | ||
| catch (TAO_DynValue_i* orig) { | ||
| ACE_DEBUG ((LM_DEBUG,ACE_TEXT(" Nested member threw indirection %@\n"), orig)); | ||
| da_members_.push_back(orig); | ||
| } | ||
| } | ||
| if (trigger_indirection && cached && depth >= 2) { | ||
| ACE_DEBUG ((LM_DEBUG,ACE_TEXT("*** INDIRECTION - THROWING CACHED POINTER %@ ***\n"), cached)); | ||
| cached->_add_ref(); | ||
| throw cached; // throw of the raw pointer | ||
| } | ||
| if (!cached) cached = this; | ||
| } | ||
| void _add_ref() { ACE_DEBUG ((LM_DEBUG, ACE_TEXT(" _add_ref on %@\n"), this)); } | ||
| }; | ||
| TAO_DynValue_i* TAO_DynValue_i::cached = nullptr; | ||
|
|
||
| int run_main (int, ACE_TCHAR*[]) | ||
| { | ||
| ACE_START_TEST (ACE_TEXT ("Compiler_Features_43_Test")); | ||
|
|
||
| int res = {}; | ||
|
|
||
| TAO_DynValue_i::cached = nullptr; | ||
| try | ||
| { | ||
| auto* result = CreateDynAnyUtils<TAO_DynValue_i>::create(true, 0); | ||
| ACE_DEBUG ((LM_DEBUG, ACE_TEXT("Success - returned %@\n"), result)); | ||
| delete result; | ||
| } | ||
| catch (...) { | ||
| ACE_ERROR ((LM_ERROR, ACE_TEXT("In outer catch\n"))); | ||
| res = -1; | ||
| } | ||
|
|
||
| ACE_END_TEST; | ||
|
|
||
| return res; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
da_members_stores raw void with no cleanup —p1andp3are leaked.*When
p0is deleted inrun_main,p0->da_members_(holdingp1asvoid*) is destroyed without deleting the pointed-to object, becausestd::vector<void*>has no element destructor.p1itself is therefore never freed, andp1->da_members_(holdingp3) leaks transitively. This is a simplified stand-in for the real TAO refcounting, but the stubs provide no_remove_ref/delete path, so LeakSanitizer/Valgrind will flag these as definite leaks.If this is intentional, a comment noting the deliberate omission of cleanup would prevent false alarms and clarify intent for future readers.
🧰 Tools
🪛 Cppcheck (2.19.0)
[error] 61-61:
#errorACE/TAO require C++17 compliance, please upgrade your compiler and/or fix the platform configuration for your environment(preprocessorErrorDirective)
🤖 Prompt for AI Agents