[SERVER-55017] iassert/tassert evaluate arguments when untriggered Created: 06/Mar/21  Updated: 29/Oct/23  Resolved: 10/Mar/21

Status: Closed
Project: Core Server
Component/s: Internal Code
Affects Version/s: None
Fix Version/s: 4.9.0

Type: Bug Priority: Major - P3
Reporter: Billy Donahue Assignee: Billy Donahue
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Problem/Incident
causes SERVER-54836 tassert() should use operator bool() Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Service Arch 2021-03-08, Service Arch 2021-03-22
Participants:

 Description   

The iassert and tassert macros immediately expand all their arguments to a C++ function call expression. The called functions (there are several overloads possible) take nontrivial objects like std::string msg and SourceLocationHolder loc.

Another consequence is that the condition is not evaluated in an if condition's bool context, which causes objects with explicit operator bool conversions to be rejected from iassert and uassert where they would not be rejected from the other asserts.
(see SERVER-54836).

An assertion has to be nearly free if the condition passes.



 Comments   
Comment by Githook User [ 10/Mar/21 ]

Author:

{'name': 'Billy Donahue', 'email': 'billy.donahue@mongodb.com', 'username': 'BillyDonahue'}

Message: SERVER-55017 fix iassert(...) and tassert(...) argument evaluation
Branch: master
https://github.com/mongodb/mongo/commit/bfbe088aabd4716348eb17602f669613f9ce6b45

Comment by Billy Donahue [ 08/Mar/21 ]

Code Review https://mongodbcr.appspot.com/749640009/

Generated at Thu Feb 08 05:35:13 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.