summaryrefslogtreecommitdiff
path: root/build2/cxx-modules/modtest/driver.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-09-28 18:03:28 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-09-28 18:03:28 +0200
commit297bc80eab5128e1cde7cd597368109a033b6cc0 (patch)
tree251806183b14a8b643b2bfe1c934c73022c90628 /build2/cxx-modules/modtest/driver.cxx
parenta00f98381c708fbba986844762368be3d0e20a6f (diff)
Update idea: C++ modules support
Add module test for Clang and VC
Diffstat (limited to 'build2/cxx-modules/modtest/driver.cxx')
-rw-r--r--build2/cxx-modules/modtest/driver.cxx51
1 files changed, 51 insertions, 0 deletions
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 <string>
+#include <iostream>
+
+// 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 <foo>
+# include <bar>
+
+// 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 <foo>
+# 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;
+}