C++/c-common PATCH to conversion from scoped enum to bool (part of 48450)

Message ID 4DA37889.6090008@redhat.com
State New
Headers show

Commit Message

Jason Merrill April 11, 2011, 9:54 p.m.
On 04/07/2011 05:41 PM, Jason Merrill wrote:
> PR 48450 has to do with SFINAE bugs, but one of them turns out to be a
> different sort of bug: we were failing to convert from a non-constant
> value of scoped enum type to bool, because that conversion was doing a
> != 0, which requires an implicit conversion to int. So now we explicitly
> convert to the underlying integral type first, and prevent c-common from
> helpfully removing it again.

...except that if the underlying type is bool, this leads to infinite 
recursion.  So use build_nop instead of convert.

Tested x86_64-pc-linux-gnu, applying to trunk and 4.6.
commit a2873eda4e9932624a2cd1ec77fb7554206b3574
Author: Jason Merrill <jason@redhat.com>
Date:   Sun Apr 10 08:33:43 2011 -0400

    	PR c++/48534
    	* cvt.c (ocp_convert): Use build_nop to convert to underlying type
    	of scoped enum.


diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c
index 6551de6..de981bc 100644
--- a/gcc/cp/cvt.c
+++ b/gcc/cp/cvt.c
@@ -731,7 +731,7 @@  ocp_convert (tree type, tree expr, int convtype, int flags)
 	  /* We can't implicitly convert a scoped enum to bool, so convert
 	     to the underlying type first.  */
 	  if (SCOPED_ENUM_P (intype) && (convtype & CONV_STATIC))
-	    e = convert (ENUM_UNDERLYING_TYPE (intype), e);
+	    e = build_nop (ENUM_UNDERLYING_TYPE (intype), e);
 	  return cp_truthvalue_conversion (e);
diff --git a/gcc/testsuite/g++.dg/cpp0x/enum10.C b/gcc/testsuite/g++.dg/cpp0x/enum10.C
new file mode 100644
index 0000000..55a1ab4
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/enum10.C
@@ -0,0 +1,9 @@ 
+// PR c++/48534
+// { dg-options -std=c++0x }
+enum class OpSE : bool;
+int main()
+  return static_cast<bool>(OpSE());