Page MenuHomePhabricator

[clang-tidy] Fix ODR violation in unittests.
ClosedPublic

Authored by NoQ on Wed, Jul 29, 6:04 PM.

Details

Summary

I debugged the problem from D84453 and D82188. The linker is not at fault - it's an ODR violation: there are two definitions for clang::tidy::test::TestCheck::registerMatchers. One test provides a non-trivial overload for registerMatchers, the other test doesn't overload this function (it only tests whether the check gets enabled when options are tweaked, so it doesn't register any matchers). When linker merges the two classes, the class without the overload may randomly win the race, and in this case the class that expects an overload appears to behave as if the function isn't called at all (because the definition in the superclass does nothing).

Put classes into anonymous namespaces to avoid the ODR violation.

Diff Detail

Event Timeline

NoQ created this revision.Wed, Jul 29, 6:04 PM
NoQ requested review of this revision.Wed, Jul 29, 6:04 PM
vsavchenko accepted this revision.Thu, Jul 30, 12:22 AM

LGTM! Thanks for all the investigative work!

This revision is now accepted and ready to land.Thu, Jul 30, 12:22 AM
gribozavr2 accepted this revision.Thu, Jul 30, 12:50 AM
njames93 accepted this revision.Thu, Jul 30, 1:50 AM

LGTM, Thanks that bug was eating away at me for a good few days.

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptThu, Jul 30, 8:53 AM
Herald added a subscriber: steakhal. · View Herald Transcript