Open kit-ty-kate opened 3 weeks ago
To be pendantic I suggest that Dune checks that the C++ compiler it uses defaults at least to C++11. This can be checked with cc
-style compilers by:
$ cc -dM -E -x c++ - < /dev/null | grep __cplusplus
#define __cplusplus 199711L
$ cc --version
Apple clang version 15.0.0 (clang-1500.3.9.4)
$ /opt/homebrew/Cellar/llvm/18.1.8/bin/clang -dM -E -x c++ - < /dev/null | grep __cplusplus
#define __cplusplus 201703L
$ /opt/homebrew/bin/gcc-14 -dM -E -x c++ - < /dev/null | grep __cplusplus
#define __cplusplus 201703L
You see here that Apple clang 15 defaults to C++98, but clang and gcc installed via Homebrew default to C++17.
MSVC defaults to C++14, so that's fine.
Note that clang-16 shipped with the new macOS 15.0 Sequoia still defaults to C++98.
@MisterDA do you want to send a PR?
I don't think that passing a specific version of C++ is the way to go… I would rather have Dune detect the version of C++ the C++ compiler defaults to, if there are C++ stubs, and pass -std=c++11
if it default to a version older than C++11. I'm not sure where that could go in Dune.
I don't think that passing a specific version of C++ is the way to go… I would rather have Dune detect the version of C++ the C++ compiler defaults to, if there are C++ stubs, and pass
-std=c++11
if it default to a version older than C++11.
If this is to avoid issues with having the option overwrite the default or a user-given -std=[...]
i don't think these are a problem at all:
-std=[...]
given to a command override the previous definition so there is no problem there eitherMakes sense.
the default would be overwritten only for OCaml 5.3 so it should be detected early when users upgrade
We could also default to C++11 for all OCaml 5 versions.
I opened https://github.com/ocaml/dune/pull/10962 to fix this
See https://github.com/ocaml/ocaml/issues/13422 OCaml 5.3 requires
-std=c++11
to be passed when C++ is used. From what i understand Dune 3 passes+x c++
automatically to the C compiler so it should probably also add this option too.