From 297bc80eab5128e1cde7cd597368109a033b6cc0 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 28 Sep 2016 18:03:28 +0200 Subject: Update idea: C++ modules support Add module test for Clang and VC --- build2/cxx-modules/modtest/driver.cxx | 51 +++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 build2/cxx-modules/modtest/driver.cxx (limited to 'build2/cxx-modules/modtest/driver.cxx') diff --git a/build2/cxx-modules/modtest/driver.cxx b/build2/cxx-modules/modtest/driver.cxx new file mode 100644 index 0000000..e782e85 --- /dev/null +++ b/build2/cxx-modules/modtest/driver.cxx @@ -0,0 +1,51 @@ +// file : driver.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2016 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +//#include +#include + +// For macro isolation test. +// +#define MODTEST_MACRO 2 + +// VC introduces module-related declarations (import, export, module). CLang +// doesn't do that implementing some transitional model interpreting headers as +// modules according to a special "module.modulemap" file and performing import +// in place of #include. +// +#if defined(MODTEST_USE_MODULES) && defined(_MSC_VER) + +import foo; +import bar; + +#else + +# include +# include + +// If we are using modules and #include directive is effectivelly converted to +// the import declaration there should be no "redefinition of foo" error. Let's +// check that. +// +# ifdef MODTEST_USE_MODULES +# include +# endif + +#endif + +using namespace std; + +int +main () +{ + foo f (3); + cerr << "foo values: " << foo_value (5) << " " << f.value () << endl + << "foo macros: " + << (MODTEST_MACRO == f.macro () ? "leaks" : "isolated") << endl; + +// cerr << f.message ("Hi") << endl; + + bar b (7); + cerr << "bar values: " << bar_value (6) << " " << b.value () << endl; +} -- cgit v1.1