diff options
author | Jay Krell <jay.krell@cornell.edu> | 2018-08-29 05:50:38 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-29 05:50:38 +0300 |
commit | 779ee790817aa5d5aa1ffa3e2f902218945e7ca6 (patch) | |
tree | e238bc6127fbe3d4fc3d092482c76b4408c2038f /configure.ac | |
parent | f0966dcd91a5c1bbdfddd90dba48826e1bc24773 (diff) |
[cxx] int vs. enum -- bit overload version (#10274)
* [cxx] int vs. enum.
There are at least three or so approaches to this.
1. Sprinkle around casts.
2. Overload operators.
2a. Bit-only (| & ^ |= &= ^=) This PR.
2b. Also math (+ - ++ -- == !=)
3. typedef to int instead (https://github.com/mono/mono/pull/10231)
They all have tradeoffs.
1. Casts: The most line damage. Not huge, but the most.
2. Overloads: New idiom to some but an old idiom. Supported in this way by windows.h even.
This is the most "C++y solution".
3. int: Highest level of source compat and semantic compat. Least line damage (just
change the declarations). Least debuggable and least typesafe.
In terms of semantic compat, even in C the guarantees aren't particularly strong.
Some enums will be int, some unsigned, depending on the values and the compiler.
Perhaps even other types, but I doubt it.
I observe C++ compilers don't tend toward unsigned the same way, so switching
to C++ will on some platforms lose unsignedness. Given we didn't have it portably
anyway, should be ok.
A typesafe enum has the properties that enum A cannot be silently assigned to enum B (ok,
there might be a warning), or from an integer.
A typesafe enum, bitfield or otherwise, can/will be shown symbolically by a debugger.
(lldb does not handle bitfields, only strict enums)
A C enum might be debuggable, w/o typesafety.
A C enum can be freely mixed with other enums and integers.
A C++ enum is more restricted.
Using typedef int, is a maybe surprising option, but does provide the closest meaning to C enum.
Per guidance, this PR also changes one enum to #defines + int.
* PR: "mono" => "g"
"T" => "type"
static_cast where it works (not to reference)
Use templatized typedef instead of macro, if it works on g++4.4.
Add test.
Provide to build eglib tests.
Borrow CXXFLAGS_COMMON from https://github.com/mono/mono/pull/10271.
Add some const to test harness.
* g++4.4 compat (not quite C++11) -- use macro, not template typedef.
* Fix real problem with aliasing seen with g++4.4.
Use attribute(may_alias) when casting pointers/references.
* Add mono/eglib/test/enum.cpp.
Diffstat (limited to 'configure.ac')
-rw-r--r-- | configure.ac | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/configure.ac b/configure.ac index a39e6fdf75c..8949284f18e 100644 --- a/configure.ac +++ b/configure.ac @@ -1022,12 +1022,17 @@ fi AC_ARG_ENABLE(cxx, [ --enable-cxx compile some code as C++]) +# mono/corefx/native has a lot of invalid C++98 in its headers +# dotnet/corefx/native looks a lot better, i.e. 44e5bdafb8d989a220c9cf1b94f31a64a6e4f052 +#CXXFLAGS_COMMON=' -std=gnu++98 -fno-exceptions -fno-rtti ' +CXXFLAGS_COMMON=' -std=gnu++0x -fno-exceptions -fno-rtti ' +# "c++0x" instead of C++11, for compat with Centos6/gcc4.4 + +AC_SUBST(CXXFLAGS_COMMON) + if test "x$enable_cxx" = "xyes"; then - # FIXME Centos6 requires a different flag for prerelease C++11. - #CXX_ADD_CFLAGS=' -xc++ -std=gnu++98 -fno-exceptions -fno-rtti ' - CXX_ADD_CFLAGS=' -xc++ -std=gnu++0x -fno-exceptions -fno-rtti ' - # "c++0x" instead of C++11, for compat with Centos6/gcc4.4 + CXX_ADD_CFLAGS=" -xc++ $CXXFLAGS_COMMON " # -std=gnu99 -xc++ is not allowed and errors. CXX_REMOVE_CFLAGS=-std=gnu99 @@ -5547,6 +5552,7 @@ mono/mini/Makefile mono/profiler/Makefile mono/eglib/Makefile mono/eglib/eglib-config.h +mono/eglib/test/Makefile m4/Makefile ikvm-native/Makefile scripts/Makefile |