000000000db409c0 t TestWebUIConfig::IsWebUIEnabled(content::BrowserContext*)
000000000db408c0 t TestWebUIConfig::TestWebUIConfig(std::__Cr::basic_string<char, std::__Cr::char_traits<char>, std::__Cr::allocator<char> > const&, std::__Cr::basic_string<char, std::__Cr::char_traits<char>, std::__Cr::allocator<char> > const&, bool)
000000000e183ba0 t TestWebUIConfig::TestWebUIConfig()
000000000db40990 t TestWebUIConfig::~TestWebUIConfig()
000000000db40970 t TestWebUIConfig::~TestWebUIConfig()
000000001f53e290 d vtable for TestWebUIConfig
--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/d7a4354e-f2c5-42cd-87b5-af49bddce25en%40chromium.org.
Yes this is an ODR violation. Thanks for pointing that out!I was expecting linker to detect duplicate definitions across the translation unit, that it looks like this is, as explicitly spec'd, not a requirement for C++ linkers, if I interpret it correctly.
Using an unnamed namespace is definitely a solution. However, duplicating symbols seems to be a very easy mistake to make in tests, and I am surprised we don't have a good way to forbid that in compile time.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CA%2BTrVVZqYm1Mtk2PN-qerGn%2B%3DNK8PFq6m32D1WLKgjR6%3D%3DRCXg%40mail.gmail.com.
If your function wasn't inline, the linker would error about the duplicate definition as you expected.
If your function wasn't inline, the linker would error about the duplicate definition as you expected.In my case IsWebUIEnabled() is not inlined. It is supposed to have symbols (see the output of nm I pasted). However, it seems that only one symbol is generated and the other is ignored in the final executable unit_tests. I was using remoteexec and it did not seem to generate .a files so I haven't checked that.
If your function wasn't inline, the linker would error about the duplicate definition as you expected.In my case IsWebUIEnabled() is not inlined.
From the perspective of a linker, what would be the difference between inline and non-inlined methods? How could a linker distinguish them, and not error on the multiple definitions of inline function?
Thank you Hans and Peter for your explanation. The term "inline" is apparently overloaded - it is either "definition-inline" as you have pointed out in my code, or "caller-inline" that I confused with. Let's ignore caller-inline in this discussion.From the perspective of a linker, what would be the difference between inline and non-inlined methods? How could a linker distinguish them, and not error on the multiple definitions of inline function?I did a quick test with godbolt on object files disassembly of inline vs. non-inline functions (diff). The only difference is that the non-inline function has an additional nop instruction after ret.This looks cryptic to me, and I would be surprised if the linker is leveraging nop to identify non-inline functions. Or if I might have missed something?
KerenOn Wed, Jul 3, 2024 at 11:30 AM Peter Kasting <pkas...@chromium.org> wrote:On Tuesday, July 2, 2024 at 6:37:40 PM UTC-7 kere...@google.com wrote:If your function wasn't inline, the linker would error about the duplicate definition as you expected.In my case IsWebUIEnabled() is not inlined."inline" in C++ means "allowed to have multiple definitions, linker is free to select any". It is distinct from whether a function has been inlined by the compiler, which there is no standardized way to control (though we have ALWAYS_INLINE and NOINLINE macros to try and tell the compiler to do one or the other).As Hans mentions, any function defined in the class declaration is implicitly an inline function, as is any function declared "inline". Whether the compiler will inline their definitions into callers is another matter.This is extremely confusing and probably the vast majority of C++ programmers do not understand it correctly.PK
--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CA%2BTrVVZrGf0zshCf8Pm6KrDzqaYK%2BvHBvBAutFs0STbFHJGdQA%40mail.gmail.com.