C++ Logo

sg15

Advanced search

Re: unimported implementation partitions

From: Nathan Sidwell <nathan_at_[hidden]>
Date: Thu, 9 Jun 2022 10:52:20 -0400
On 6/9/22 10:45, Boris Kolpackov via SG15 wrote:
> Gabriel Dos Reis <gdr_at_[hidden]> writes:
>
>> [Boris]
>>> For example, the implementation partition may include a unit test
>>> (because that's the only way to access the private parts) which
>>> is registered with the test harness.
>>
>> How would that work in practice (concrete example)?
>
> The following example works with GCC 12.

That works because the module initializers are also placed in the .init
section. It was hard not to do so (because of the way that bit of the
compiler was structured), but is the question I am asking.

Do not take GCC's behaviour here as evidence that it is the minimum of
what should be happening.

>
> // file: tester.hxx
> //
> struct test_registrar
> {
> static void (*test) ();
> explicit test_registrar (void (*t) ()) {test = t;}
> };
>
> // file: tester.cxx
> //
> #include "tester.hxx"
>
> void (*test_registrar::test) ();
>
> int main ()
> {
> test_registrar::test ();
> }
>
> // file: hello-printer.mxx
> //
> module;
> #include <cassert>
> #include "tester.hxx"
> module hello:print;
>
> static void
> unit_test ()
> {
> assert (false);
> }
>
> test_registrar init (&unit_test);
>
> // buidfile
> //
> exe{tester}: cxx{tester} mxx{hello-printer}
> _______________________________________________
> SG15 mailing list
> SG15_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/sg15


-- 
Nathan Sidwell

Received on 2022-06-09 14:52:23