Repository: dtolnay/cxx (language: rust)

Issue:
-std=c++11 is not required on MSVC
Building on x86_64-pc-windows-msvc currently emits this warning:

```console
warning: cl : Command line warning D9002 : ignoring unknown option '-std=c++11'
```

According to https://docs.microsoft.com/en-us/cpp/build/reference/std-specify-language-standard-version?view=vs-2019, C++11 is the default with flags `/std:c++14` and `/std:c++17` for the newer standards.

We should find a way to pass `-std=c++11` only when it's required, such as on x86_64-apple-darwin where C++98 is the default. https://opensource.apple.com/source/clang/clang-800.0.42.1/src/tools/clang/www/cxx_status.html

```console
running: "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-Wall" "-Wextra" "-o" "/Users/travis/build/dtolnay/cxx/target/debug/build/cxx-f198c1b742072022/out/src/cxxbridge.o" "-c" "src/cxxbridge.cc"

In file included from src/cxxbridge.cc:1:
src/../include/cxxbridge.h:9:18: warning: 'final' keyword is a C++11 extension [-Wc++11-extensions]
class RustString final {
                 ^
```


Discussion / hints:

Fix patch:
diff --git a/README.md b/README.md
index 1b1611d71..f81963648 100644
--- a/README.md
+++ b/README.md
@@ -228,7 +228,7 @@ cxx-build = "0.3"
 fn main() {
     cxx_build::bridge("src/main.rs")  // returns a cc::Build
         .file("../demo-cxx/demo.cc")
-        .flag("-std=c++11")
+        .flag_if_supported("-std=c++11")
         .compile("cxxbridge-demo");
 
     println!("cargo:rerun-if-changed=src/main.rs");
diff --git a/build.rs b/build.rs
index 16837f36a..9a071fe58 100644
--- a/build.rs
+++ b/build.rs
@@ -3,7 +3,7 @@ fn main() {
         .file("src/cxx.cc")
         .cpp(true)
         .cpp_link_stdlib(None) // linked via link-cplusplus crate
-        .flag("-std=c++11")
+        .flag_if_supported("-std=c++11")
         .compile("cxxbridge03");
     println!("cargo:rerun-if-changed=src/cxx.cc");
     println!("cargo:rerun-if-changed=include/cxx.h");
diff --git a/demo-rs/build.rs b/demo-rs/build.rs
index edbb28196..e4792c2a1 100644
--- a/demo-rs/build.rs
+++ b/demo-rs/build.rs
@@ -1,7 +1,7 @@
 fn main() {
     cxx_build::bridge("src/main.rs")
         .file("../demo-cxx/demo.cc")
-        .flag("-std=c++11")
+        .flag_if_supported("-std=c++11")
         .compile("cxxbridge-demo");
 
     println!("cargo:rerun-if-changed=src/main.rs");
diff --git a/gen/build/src/lib.rs b/gen/build/src/lib.rs
index b33e19282..14683b688 100644
--- a/gen/build/src/lib.rs
+++ b/gen/build/src/lib.rs
@@ -16,7 +16,7 @@
 //! fn main() {
 //!     cxx_build::bridge("src/main.rs")
 //!         .file("../demo-cxx/demo.cc")
-//!         .flag("-std=c++11")
+//!         .flag_if_supported("-std=c++11")
 //!         .compile("cxxbridge-demo");
 //!
 //!     println!("cargo:rerun-if-changed=src/main.rs");
@@ -83,7 +83,7 @@ pub fn bridge(rust_source_file: impl AsRef<Path>) -> cc::Build {
 /// let source_files = vec!["src/main.rs", "src/path/to/other.rs"];
 /// cxx_build::bridges(source_files)
 ///     .file("../demo-cxx/demo.cc")
-///     .flag("-std=c++11")
+///     .flag_if_supported("-std=c++11")
 ///     .compile("cxxbridge-demo");
 /// ```
 pub fn bridges(rust_source_files: impl IntoIterator<Item = impl AsRef<Path>>) -> cc::Build {
diff --git a/src/lib.rs b/src/lib.rs
index 78aba3d54..7e6ece4f9 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -233,7 +233,7 @@
 //! fn main() {
 //!     cxx_build::bridge("src/main.rs")  // returns a cc::Build
 //!         .file("../demo-cxx/demo.cc")
-//!         .flag("-std=c++11")
+//!         .flag_if_supported("-std=c++11")
 //!         .compile("cxxbridge-demo");
 //!
 //!     println!("cargo:rerun-if-changed=src/main.rs");


Test patch:
diff --git a/tests/ffi/build.rs b/tests/ffi/build.rs
index 2c96d7325..f6fa59ea6 100644
--- a/tests/ffi/build.rs
+++ b/tests/ffi/build.rs
@@ -6,6 +6,6 @@ fn main() {
     let sources = vec!["lib.rs", "module.rs"];
     cxx_build::bridges(sources)
         .file("tests.cc")
-        .flag("-std=c++11")
+        .flag_if_supported("-std=c++11")
         .compile("cxx-test-suite");
 }