Merge pull request #3495 from pherl/c++11

Add std::forward and std::move autoconf check
diff --git a/CHANGES.txt b/CHANGES.txt
index 110fb06..1f1dd6d 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,11 +1,11 @@
-2017-08-01 version 3.4.0 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript)
+2017-08-14 version 3.4.0 (C++/Java/Python/PHP/Objective-C/C#/Ruby/JavaScript)
   Planned Future Changes
   * There are some changes that are not included in this release but are planned
     for the near future
       - Preserve unknown fields in proto3: We are going to bring unknown fields
         back into proto3. In this release, some languages start to support
         preserving unknown fields in proto3, controlled by flags/options. Some
-        languages also introduce explict APIs to drop unknown fields for
+        languages also introduce explicit APIs to drop unknown fields for
         migration. Please read the change log sections by languages for details.
         For general timeline and plan:
 
@@ -45,6 +45,7 @@
 
       $ protoc --cpp_out=table_driven_parsing,table_driven_serialization:./ \
         test.proto
+
   * lite generator parameter supported by the generator. Once set, all generated
     files, use lite runtime regardless of the optimizer_for setting in the
     .proto file.
diff --git a/protoc-artifacts/README.md b/protoc-artifacts/README.md
index 5062920..17eb77f 100644
--- a/protoc-artifacts/README.md
+++ b/protoc-artifacts/README.md
@@ -72,6 +72,7 @@
 - Windows (x86_32 and x86_64) with
  - Cygwin64 with MinGW compilers (x86_64)
  - MSYS with MinGW32 (x86_32)
+ - Cross compile in Linux with MinGW-w64 (x86_32, x86_64)
 - MacOSX (x86_32 and x86_64)
 
 As for MSYS2/MinGW64 for Windows: protoc will build, but it insists on
@@ -98,6 +99,9 @@
 A 32-bit artifact can be deployed from a 64-bit host with
 ``-Dos.detected.arch=x86_32``
 
+A windows artifact can be deployed from a linux machine with
+``-Dos.detected.name=windows``
+
 When you have done deployment for all platforms, go to
 https://oss.sonatype.org/#stagingRepositories, verify that the staging
 repository has all the binaries, close and release this repository.
@@ -173,5 +177,7 @@
  - Centos 6.6 (within Docker 1.6.1)
  - Ubuntu 14.04.2 64-bit
 - Windows x86_32: MSYS with ``mingw32-gcc-g++ 4.8.1-4`` on Windows 7 64-bit
+- Windows x86_32: Cross compile with ``i686-w64-mingw32-g++ 4.8.2`` on Ubuntu 14.04.2 64-bit
 - Windows x86_64: Cygwin64 with ``mingw64-x86_64-gcc-g++ 4.8.3-1`` on Windows 7 64-bit
+- Windows x86_64: Cross compile with ``x86_64-w64-mingw32-g++ 4.8.2`` on Ubuntu 14.04.2 64-bit
 - Mac OS X x86_32 and x86_64: Mac OS X 10.9.5
diff --git a/protoc-artifacts/build-protoc.sh b/protoc-artifacts/build-protoc.sh
index e31948e..57523a4 100755
--- a/protoc-artifacts/build-protoc.sh
+++ b/protoc-artifacts/build-protoc.sh
@@ -185,8 +185,6 @@
     fi
   elif [[ "$OS" == windows ]]; then
     # Cross-compilation for Windows
-    # TODO(zhangkun83) MinGW 64 always adds dependency on libwinpthread-1.dll,
-    # which is undesirable for repository deployment.
     CONFIGURE_ARGS="$CONFIGURE_ARGS"
     if [[ "$ARCH" == x86_64 ]]; then
       CONFIGURE_ARGS="$CONFIGURE_ARGS --host=x86_64-w64-mingw32"
@@ -215,8 +213,11 @@
 
 # Statically link libgcc and libstdc++.
 # -s to produce stripped binary.
-# And they don't work under Mac.
-if [[ "$OS" != osx ]]; then
+if [[ "$OS" == windows ]]; then
+  # Also static link libpthread required by mingw64
+  LDFLAGS="$LDFLAGS -static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -lpthread -s"
+elif [[ "$OS" != osx ]]; then
+  # And they don't work under Mac.
   LDFLAGS="$LDFLAGS -static-libgcc -static-libstdc++ -s"
 fi
 
diff --git a/src/google/protobuf/stubs/mathlimits.h b/src/google/protobuf/stubs/mathlimits.h
index 275d953..2391ac4 100644
--- a/src/google/protobuf/stubs/mathlimits.h
+++ b/src/google/protobuf/stubs/mathlimits.h
@@ -43,18 +43,23 @@
 #ifndef UTIL_MATH_MATHLIMITS_H__
 #define UTIL_MATH_MATHLIMITS_H__
 
-// GCC 4.9 has a bug that makes it impossible to use isinf and isnan when both
-// <math.h> and <cmath> get pulled into the same translation unit.
-// Unfortunately it is difficult to prevent this from happening, so to work
-// around the problem we use std::isinf and std::isnan from <cmath> for C++11
-// builds and otherwise use the plain isinf and isnan functions from <math.h>.
 // Note that for Windows we do something different because it does not support
 // the plain isinf and isnan.
 #if __cplusplus >= 201103L
+// GCC 4.9 has a bug that makes isinf and isnan ambigious when both <math.h>
+// and <cmath> get pulled into the same translation unit. We use the ones in
+// std:: namespace explicitly for C++11
 #include <cmath>
+#define GOOGLE_PROTOBUF_USE_STD_CMATH
+#elif _GLIBCXX_USE_C99_MATH && !_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC
+// libstdc++ <cmath> header undefines the global macros and put functions in
+// std:: namespace even before C++11. Use the ones in std:: instead too.
+#include <cmath>
+#define GOOGLE_PROTOBUF_USE_STD_CMATH
 #else
 #include <math.h>
 #endif
+
 #include <string.h>
 
 #include <cfloat>
@@ -229,7 +234,7 @@
 // For non-Windows builds we use the std:: versions of isinf and isnan if they
 // are available; see the comment about <cmath> at the top of this file for the
 // details on why we need to do this.
-#if __cplusplus >= 201103L
+#ifdef GOOGLE_PROTOBUF_USE_STD_CMATH
 #define ISINF std::isinf
 #define ISNAN std::isnan
 #else