diff options
author | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
---|---|---|
committer | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
commit | 554fd8c5195424bdbcabf5de30fdc183aba391bd (patch) | |
tree | 976dc5ab7fddf506dadce60ae936f43f58787092 /gcc/testsuite/g++.dg/cpp0x/scoped_enum.C | |
download | cbb-gcc-4.6.4-upstream.tar.bz2 cbb-gcc-4.6.4-upstream.tar.xz |
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig;
imported gcc-4.6.4 source tree from verified upstream tarball.
downloading a git-generated archive based on the 'upstream' tag
should provide you with a source tree that is binary identical
to the one extracted from the above tarball.
if you have obtained the source via the command 'git clone',
however, do note that line-endings of files in your working
directory might differ from line-endings of the respective
files in the upstream repository.
Diffstat (limited to 'gcc/testsuite/g++.dg/cpp0x/scoped_enum.C')
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/scoped_enum.C | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/cpp0x/scoped_enum.C b/gcc/testsuite/g++.dg/cpp0x/scoped_enum.C new file mode 100644 index 000000000..c52a3fe76 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/scoped_enum.C @@ -0,0 +1,76 @@ +// { dg-options "-std=c++0x" } +enum class Color1 { + Red, + Green, + Blue +}; + +enum struct Color2 { + Red, // { dg-error "previously declared here" } + Orange, + Yellow, + Green, + Blue, + Indigo = Green + 2, + Violet, + Red // { dg-error "redefinition" } +}; + +enum Color { + Red, Green, Blue +}; + +enum class Color3 { + Red +}; + +enum Color color; +enum Color3 color3; + +void f(int); +void f2(Color3); + +void g() +{ + int i = 0; + f(color); // okay: unscoped enum + f(color3); // { dg-error "cannot convert" } + f2(color); // { dg-error "cannot convert" } + f2(color3); + f2(i); // { dg-error "cannot convert" } + i = color3; // { dg-error "cannot convert" } + color3 = i; // { dg-error "cannot convert" } + f(static_cast<int>(color3)); // okay + + int a[5]; + a[color3]; // { dg-error "array subscript is not an integer" } + + bool b = color3; // { dg-error "cannot convert" } +} + +void h() +{ + Color1 c1 = Color1::Red; + Color2 c2 = Color1::Red; // { dg-error "cannot convert" } + c2 = Color1::Red; // { dg-error "cannot convert" } + + c2 = Color2::Red; + int c3 = Color::Red; +} + +template<typename T, T value> +struct constant { }; + +template<typename T> +int& sfinae(constant<T, T::Green>*); + +float& sfinae(void*); + +void sfinae_test() +{ + int& test1 = sfinae((constant<Color1, Color1::Green>*)0); + int& test2 = sfinae((constant<Color2, Color2::Green>*)0); + float& test3 = sfinae((constant<Color1, Color1::Red>*)0); + int& test4 = sfinae((constant<Color, Green>*)0); + float& test5 = sfinae((constant<Color, Red>*)0); +} |