Bug 1077887: Work around old GCC "enum class" bug, r=mmc
--- a/security/pkix/include/pkix/Result.h
+++ b/security/pkix/include/pkix/Result.h
@@ -144,20 +144,20 @@ MOZILLA_PKIX_ENUM_CLASS Result
// Returns the stringified name of the given result, e.g. "Result::Success",
// or nullptr if result is unknown (invalid).
const char* MapResultToName(Result result);
// We write many comparisons as (x != Success), and this shortened name makes
// those comparisons clearer, especially because the shortened name often
// results in less line wrapping.
//
-// Visual Studio before VS2013 does not support "enum class," so
-// Result::Success will already be visible in this scope, and compilation will
-// fail if we try to define a variable with that name here.
-#if !defined(_MSC_VER) || (_MSC_VER >= 1700)
+// If MOZILLA_PKIX_ENUM_CLASS doesn't expand to "enum class" then
+// Result::Success will already be in scope, and compilation would fail if we
+// were to try to define a variable named "Success" here.
+#ifdef MOZILLA_PKIX_ENUM_CLASS_REALLY_IS_ENUM_CLASS
static const Result Success = Result::Success;
#endif
inline bool
IsFatalError(Result rv)
{
return (static_cast<unsigned int>(rv) & FATAL_ERROR_FLAG) != 0;
}
--- a/security/pkix/include/pkix/enumclass.h
+++ b/security/pkix/include/pkix/enumclass.h
@@ -17,26 +17,28 @@
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-// Work around missing std::bind, std::ref, std::cref in older compilers. This
-// implementation isn't intended to be complete; rather, it is the minimal
-// implementation needed to make our use of std::bind work.
-
#ifndef mozilla_pkix__enumclass_h
#define mozilla_pkix__enumclass_h
#if defined(_MSC_VER) && (_MSC_VER < 1700)
// Microsoft added support for "enum class" in Visual C++ 2012. Before that,
// Visual C++ has supported typed enums for longer than that, but using typed
// enums results in C4480: nonstandard extension used: specifying underlying
// type for enum.
#define MOZILLA_PKIX_ENUM_CLASS __pragma(warning(suppress: 4480)) enum
+#elif defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ < 407)
+// GCC before version 4.7 may crash when compiling code that static_casts a
+// value of scoped typed enum type. See
+// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48106.
+#define MOZILLA_PKIX_ENUM_CLASS enum
#else
#define MOZILLA_PKIX_ENUM_CLASS enum class
+#define MOZILLA_PKIX_ENUM_CLASS_REALLY_IS_ENUM_CLASS
#endif
#endif // mozilla_pkix__enumclass_h