https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123728
--- Comment #6 from Andy Lutomirski <luto at kernel dot org> ---
(In reply to Andrew Pinski from comment #5)
> Yes there is an heurstic to try to disable the warning. But that heurstic
> does not change the fact on there might be an ODR issue involved here. Also
> the (template) type here is not defined in the main source file, it is
> defined in the header.
I still don't see any real ODR issue here. What is GCC actually trying to warn
me about?
Unless I'm missing something rather bizarre about C++, the ODR already requires
that all definitions Test be identical including the typedef ParamType. So if
I duplicated the entire definition of LocalEnum and Test in a second cpp file,
or if I moved them into a header, I would have a problem. But if GCC really
meant to warn about that, it should also warn about this:
namespace { struct LocalEnum {}; }
struct Test {
typedef LocalEnum ParamType;
void func()
{
ParamType();
}
};
which is every bit as much an ODR violation if I duplicate it into a second TU.
But GCC does not warn about that.
The actual code that I reduced this from is (with names changed to protect the
innocent):
namespace {
enum Mode {
A, B,
};
class TestFamily : public testing::TestWithParam<Mode> {
/* various contents that involve GetParam() */
};
}
TEST_P(TestFamily, SomeTest) {
/* test code here */
}
There is nothing here that smells even remotely like an ODR violation. I'm
using an anonymous namespace to *prevent* a possible ODR violation in case some
other test file also has a class called TestFamily. The entire test class is
in the anonymous namespace. The test case itself references it and registers
itself with gtest.
I've had the Wsubobject-linkage warning disabled for years in this file. I'd
rather be able to re-enable it, and I think I presented a fairly compelling
reduction of the hole in GCC's heuristic that is giving that I consider to be a
false positive. If you don't want to improve the heuristic, fine -- I'll keep
on disabling the warning. (Actually I'll move the TEST_P into the anonymous
namespace, which also makes the warning go away, and which I probably should
have done earlier.)
At the end of the day, this is all a heuristic. I think that the warning would
be more useful if it had fewer false positives, but that's the GCC community's
call, not mine.