Bug 1392643 Turn on c++14 for MinGW globally draft
authorTom Ritter <tom@mozilla.com>
Fri, 22 Sep 2017 12:26:42 -0500
changeset 669186 0217ba53883b1c31556085bcb52d6c80778169b4
parent 669185 af176b804d791ab61d5040e5f90b4d7da712bf7f
child 732882 dd0840579a8bfd6aedcfea2230fa7ce95fa717ef
push id81244
push userbmo:tom@mozilla.com
push dateFri, 22 Sep 2017 17:27:02 +0000
bugs1392643
milestone58.0a1
Bug 1392643 Turn on c++14 for MinGW globally Technically this turns on gnu++14. I encountered a few errors when using c++14: 1) _USE_MATH_DEFINES needed to be defined for MinGW 2) MinGW did not define _finite under c++14 3) MinGW's float.h did not define Microsoft specific float functions under c++14 All of these were because c++14 defines _STRICT_ANSI_ which MinGW obeys and avoids defining certain functions. The first two could be patched around, but the third was a blocker, so we switched to gnu++14 MozReview-Commit-ID: 6Y7gEQgApYp
build/moz.configure/toolchain.configure
python/mozbuild/mozbuild/test/configure/test_toolchain_configure.py
--- a/build/moz.configure/toolchain.configure
+++ b/build/moz.configure/toolchain.configure
@@ -369,23 +369,34 @@ def check_compiler(compiler, language, t
     # example)
     if info.language == 'C' and info.language_version != 199901:
         if info.type in ('clang-cl', 'clang', 'gcc'):
             append_flag('-std=gnu99')
 
     # Note: MSVC, while supporting C++11, still reports 199711L for __cplusplus.
     # Note: this is a strict version check because we used to always add
     # -std=gnu++11.
+    draft_cxx14_version = 201300
+    cxx14_version = 201402
     if info.language == 'C++':
-        if info.type in ('clang', 'gcc') and info.language_version != 201103:
-            append_flag('-std=gnu++11')
-        # MSVC 2015 headers include C++14 features, but don't guard them
-        # with appropriate checks.
-        if info.type == 'clang-cl' and info.language_version != 201402:
-            append_flag('-std=c++14')
+        if target.kernel != 'WINNT':
+            if info.type in ('clang', 'gcc') and info.language_version != 201103:
+                append_flag('-std=gnu++11')
+        else:
+            if info.type == 'clang' and info.language_version != 201103:
+                append_flag('-std=gnu++11')
+            # MSVC 2015 headers include C++14 features, but don't guard them
+            # with appropriate checks.
+            if info.type == 'clang-cl' and info.language_version != cxx14_version:
+                append_flag('-std=c++14')
+            # GCC 4.9 indicates that it implements draft C++14 features
+            # instead of the full language.
+            elif info.type == 'gcc' and not \
+                (info.language_version == draft_cxx14_version or info.language_version == cxx14_version):
+                append_flag('-std=gnu++14')
 
     # We force clang-cl to emulate Visual C++ 2015 Update 3.
     if info.type == 'clang-cl' and info.version != '19.00.24213':
         # This flag is a direct clang-cl flag that doesn't need -Xclang,
         # add it directly.
         flags.append('-fms-compatibility-version=19.00.24213')
 
     # Check compiler target
old mode 100644
new mode 100755
--- a/python/mozbuild/mozbuild/test/configure/test_toolchain_configure.py
+++ b/python/mozbuild/mozbuild/test/configure/test_toolchain_configure.py
@@ -32,28 +32,36 @@ DEFAULT_C11 = {
 DEFAULT_CXX_97 = {
     '__cplusplus': '199711L',
 }
 
 DEFAULT_CXX_11 = {
     '__cplusplus': '201103L',
 }
 
+DRAFT_CXX_14 = {
+    '__cplusplus': '201300L',
+}
+
 DEFAULT_CXX_14 = {
     '__cplusplus': '201402L',
 }
 
 SUPPORTS_GNU99 = {
     '-std=gnu99': DEFAULT_C99,
 }
 
 SUPPORTS_GNUXX11 = {
     '-std=gnu++11': DEFAULT_CXX_11,
 }
 
+SUPPORTS_GNUXX14 = {
+    '-std=gnu++14': DEFAULT_CXX_14,
+}
+
 SUPPORTS_CXX14 = {
     '-std=c++14': DEFAULT_CXX_14,
 }
 
 
 @memoize
 def GCC_BASE(version):
     version = Version(version)
@@ -71,23 +79,26 @@ def GCC_BASE(version):
 def GCC(version):
     return GCC_BASE(version) + SUPPORTS_GNU99
 
 
 @memoize
 def GXX(version):
     return GCC_BASE(version) + DEFAULT_CXX_97 + SUPPORTS_GNUXX11
 
+SUPPORTS_DRAFT_CXX14_VERSION = {
+    '-std=gnu++14': DRAFT_CXX_14,
+}
 
 GCC_4_7 = GCC('4.7.3')
 GXX_4_7 = GXX('4.7.3')
 GCC_4_9 = GCC('4.9.3')
-GXX_4_9 = GXX('4.9.3')
+GXX_4_9 = GXX('4.9.3') + SUPPORTS_DRAFT_CXX14_VERSION
 GCC_5 = GCC('5.2.1') + DEFAULT_C11
-GXX_5 = GXX('5.2.1')
+GXX_5 = GXX('5.2.1') + SUPPORTS_GNUXX14
 
 GCC_PLATFORM_LITTLE_ENDIAN = {
     '__BYTE_ORDER__': 1234,
 }
 
 GCC_PLATFORM_BIG_ENDIAN = {
     '__BYTE_ORDER__': 4321,
 }
@@ -158,26 +169,29 @@ def CLANG_BASE(version):
 @memoize
 def CLANG(version):
     return GCC_BASE('4.2.1') + CLANG_BASE(version) + SUPPORTS_GNU99
 
 
 @memoize
 def CLANGXX(version):
     return (GCC_BASE('4.2.1') + CLANG_BASE(version) + DEFAULT_CXX_97 +
-            SUPPORTS_GNUXX11)
+            SUPPORTS_GNUXX11 + SUPPORTS_GNUXX14)
 
 
 CLANG_3_3 = CLANG('3.3.0') + DEFAULT_C99
 CLANGXX_3_3 = CLANGXX('3.3.0')
 CLANG_3_6 = CLANG('3.6.2') + DEFAULT_C11
 CLANGXX_3_6 = CLANGXX('3.6.2') + {
     '-std=gnu++11': {
         '__has_feature(cxx_alignof)': '1',
     },
+    '-std=gnu++14': {
+        '__has_feature(cxx_alignof)': '1',
+    },
 }
 
 
 def CLANG_PLATFORM(gcc_platform):
     base = {
         '--target=x86_64-linux-gnu': GCC_PLATFORM_X86_64_LINUX[None],
         '--target=x86_64-darwin11.2.0': GCC_PLATFORM_X86_64_OSX[None],
         '--target=i686-linux-gnu': GCC_PLATFORM_X86_LINUX[None],
@@ -896,19 +910,31 @@ class WindowsToolchainTest(BaseToolchain
         language='C++',
     )
     CLANG_3_3_RESULT = LinuxToolchainTest.CLANG_3_3_RESULT
     CLANGXX_3_3_RESULT = LinuxToolchainTest.CLANGXX_3_3_RESULT
     CLANG_3_6_RESULT = LinuxToolchainTest.CLANG_3_6_RESULT
     CLANGXX_3_6_RESULT = LinuxToolchainTest.CLANGXX_3_6_RESULT
     GCC_4_7_RESULT = LinuxToolchainTest.GCC_4_7_RESULT
     GCC_4_9_RESULT = LinuxToolchainTest.GCC_4_9_RESULT
-    GXX_4_9_RESULT = LinuxToolchainTest.GXX_4_9_RESULT
+    GXX_4_9_RESULT = CompilerResult(
+        flags=['-std=gnu++14'],
+        version='4.9.3',
+        type='gcc',
+        compiler='/usr/bin/g++',
+        language='C++',
+    )
     GCC_5_RESULT = LinuxToolchainTest.GCC_5_RESULT
-    GXX_5_RESULT = LinuxToolchainTest.GXX_5_RESULT
+    GXX_5_RESULT = CompilerResult(
+        flags=['-std=gnu++14'],
+        version='5.2.1',
+        type='gcc',
+        compiler='/usr/bin/g++-5',
+        language='C++',
+    )
 
     # VS2015u3 or greater is required.
     def test_msvc(self):
         self.do_toolchain_test(self.PATHS, {
             'c_compiler': self.VS_2015u3_RESULT,
             'cxx_compiler': self.VSXX_2015u3_RESULT,
         })