C++ Logo


Advanced search

Re: unimported implementation partitions

From: Gabriel Dos Reis <gdr_at_[hidden]>
Date: Thu, 9 Jun 2022 15:07:39 +0000
Thanks for the example. I don't see anything in there that falls under the stronger guarantees that C++-20 provides for dynamic initialization - isn't the below just "business as usual" in pre-C++20?

-- Gaby

-----Original Message-----
From: Boris Kolpackov <boris_at_[hidden]>
Sent: Thursday, June 9, 2022 7:45 AM
To: Gabriel Dos Reis <gdr_at_[hidden]>
Cc: Gabriel Dos Reis via SG15 <sg15_at_[hidden]>; C++ Core Language Working Group <core_at_[hidden]>; Nathan Sidwell <nathan_at_[hidden]>
Subject: Re: [SG15] unimported implementation partitions

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.

// 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
#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}

Received on 2022-06-09 15:07:42