catchorg / catchorg/Catch2

Careless use of StringMaker can easily lead to ODR violations

Open
#2,298 3 comments 3 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
21.5k
Forks
3.5k
Avg merge
3d 16h
Merged PRs (30d)
2

Description

When adding new specializations of StringMaker in a program it's fairly natural to start adding them in a specific compilation unit to get started.
If the class is used in any other compilation unit where catch stringifies a value of that type this is a ODR violation which is one of our beloved "no diagnostics required" gotchas in c++. The result is that the use of StringMaker fails to work most of the time when adding it to existing projects without a central place for such things.

Ideally catch would find a way to make this kind of usage not a ODR violation. Maybe something is possible with use of "static" and/or anonymous namespaces. Or maybe it's not possible or too costly.

In the meantime it might be nice to add a "troubleshooting" section in the documentation to remind users that all compilation units that let a specific type come anywhere close to catch need to have exactly the same StringMaker specialization for that type.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.