Skip to content
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

Remove copy/assign/move tests in testAttributes() #1922

Merged

Conversation

cary-ilm
Copy link
Member

When we implemented the "rule of 5" (PR #601) in 2019, I added code to testAttributes.cpp to validate the behavior, specifically related to the TypedAttribute class, but in retrospect, this code isn't reliable, so I propose eliminating the test altogether.

The test counts invocations of the various constructors, destructors, and move/assignment operators, expecting them to be consistent, but compilers can optionally optimize some of these operations away, producing inconsistent results.

In particular, a Debug build on Windows produces different results from a Release build. In particular, this code:

TestType func()
{
    TestType t;
    return t;
}

invokes the move constructor in debug, but a "Release" build optimizes the object away entirely.

Our CI has not historically tested a Windows Debug build, which explains why we never caught this. The exact behavior may have also changed with C++17. All the more reason to avoid such picky tests.

This does not change the library code, only the tests that I added in #601 in 2019.

When we implemented the "rule of 5" (PR AcademySoftwareFoundation#601) in 2019, I added code to
testAttributes.cpp to validate the behavior, specifically related to
the TypedAttribute class, but in retrospect, this code isn't reliable,
so I propose eliminating the test altogether.

The test counts invocations of the various constructors, destructors,
and move/assignment operators, expecting them to be consistent, but
compilers can optionally optimize some of these operations away,
producing inconsistent results.

In particular, a Debug build on Windows produces different results
from a Release build. Our CI has not historically tested a Windows
Debug build, which explains why we never caught this. The exact
behavior may have also changed with C++17. All the more reason to
avoid such picky tests.

This does not change the library code, only the tests.

Signed-off-by: Cary Phillips <[email protected]>
@cary-ilm cary-ilm merged commit c302e2d into AcademySoftwareFoundation:main Nov 20, 2024
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants