Bug 48534 - [C++0x][SFINAE] Compiler break down on explicit scoped enum => bool conversion
Summary: [C++0x][SFINAE] Compiler break down on explicit scoped enum => bool conversion
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: 4.6.1
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-09 21:22 UTC by Daniel Krügler
Modified: 2011-04-12 00:29 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Krügler 2011-04-09 21:22:02 UTC
The following code should be ill-formed, but is not:

//--------------
template<class T>
T&& create();

template<class T, class U,
 class = decltype(static_cast<T>(create<U>()))
>
char f(int);

template<class, class>
char (&f(...))[2];

enum class SEB : bool;

static_assert(sizeof(f<bool, SEB>(0)) == 1, "Error"); // #
something that went wrong...; // Should be ill-formed, but is not
//--------------

After the line marked with # the compiler does no longer compile code, but dies a silent death. Any following lines are ignored.

It seems that this is specifically isolated to a conversion from a scoped enum *with underlying type bool* to bool.
Comment 1 Daniel Krügler 2011-04-11 07:40:56 UTC
I would like to add that the "silent-death" behaviour seems to be an unfortunate behaviour of my Cygwin environment. In non-Cygwin environments that program provokes a compiler segmentation fault, thus the problem is real, but the description of the observable behaviour possibly misleading.
Comment 2 Jason Merrill 2011-04-11 22:00:39 UTC
Author: jason
Date: Mon Apr 11 22:00:31 2011
New Revision: 172284

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=172284
Log:
	PR c++/48534
	* cvt.c (ocp_convert): Use build_nop to convert to underlying type
	of scoped enum.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/enum10.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/cvt.c
    trunk/gcc/testsuite/ChangeLog
Comment 3 Jason Merrill 2011-04-12 00:20:36 UTC
Author: jason
Date: Tue Apr 12 00:20:32 2011
New Revision: 172294

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=172294
Log:
	PR c++/48534
	* cvt.c (ocp_convert): Use build_nop to convert to underlying type
	of scoped enum.

Added:
    branches/gcc-4_6-branch/gcc/testsuite/g++.dg/cpp0x/enum10.C
Modified:
    branches/gcc-4_6-branch/gcc/cp/ChangeLog
    branches/gcc-4_6-branch/gcc/cp/cvt.c
    branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
Comment 4 Jason Merrill 2011-04-12 00:29:12 UTC
Fixed for 4.6.1/4.7