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.
This is an attempt to reproduce the ODR failure I reported on Slack #cpp. This should have CI failures.
Slack discussion:
sherm1 [2:10 PM]
TL;DR: Likely not a good idea to rely on the address of function static variables to be invariant across all executing code.
I ran into a case where depending on a static object to have the same address in all the code using it failed, specifically in python test cases, which I believe use a shared library not used in other tests(?). I had a never-destroyed "dummy" value defined like this in
cache.h
:I was using
ptr==&dummy
as a flag to tell me that ptr wasn't set to anything useful. ADRAKE_DEMAND(ptr==&dummy)
failed in a case where it should have succeeded. Switching to an explicit bool flag to indicate whether ptr is meaningful fixed the problem (should have done that in the first place!).I speculate that this would have worked if I'd put the definition of dummy() in a .cc rather than a header (didn't try that as a fix since the mechanism seems brittle). (edited)
jwnimmer-tri [2:18 PM]
@sherm1 That result would indicate a build system misconfiguration. It is supposed to work. Can you post a repro for us? Which test failed? (edited)
Possibly it is something like #8908, where we were violating ODR. I also noted in #python that the pydrake bindings for
//examples
code are also broken with respect to ODR.This change is