You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I found an unexpected failure test case in ScopeGuardTest.cpp on VS2022 today. I'm really confused.
At first, the TESTThrowingCleanupAction test case failed on VS2022 all the time. Then I checked the copy-constructor and found the ScopeGuard use std::ref to wrap a throwable functor.
Interestingly, I noticed that msvc adds "const" specifier to their std::ref implementations as follows:
The member var scopeExitExecuted_ could be changed by operator(), why const specifier can be added here? In the past, I thought const before function body means no changes will be made to the members, but it seems incorrect. What does this const actually do?
Which version should choose if I need to write sth like this? const or non-const version? Does the chosen version has the portability on other platforms?
The text was updated successfully, but these errors were encountered:
ruiyuanlu
changed the title
a test case in ScopeGuardTest.cpp failure due to missing "const" specifier on VS2022
a test failure in ScopeGuardTest.cpp due to missing "const" specifier on VS2022
Mar 10, 2024
Hi, I found an unexpected failure test case in ScopeGuardTest.cpp on VS2022 today. I'm really confused.
At first, the TESTThrowingCleanupAction test case failed on VS2022 all the time. Then I checked the copy-constructor and found the ScopeGuard use
std::ref
to wrap a throwable functor.Interestingly, I noticed that msvc adds "const" specifier to their
std::ref
implementations as follows:I guess
cosnt
/non-const
specifier might make things differet. So I addedconst
as:And then everything goes just fine.
But I'm confused:
scopeExitExecuted_
could be changed by operator(), why const specifier can be added here? In the past, I thought const before function body means no changes will be made to the members, but it seems incorrect. What does thisconst
actually do?The text was updated successfully, but these errors were encountered: