Commit 60662d5f by Jason Merrill Committed by Jason Merrill

re PR c++/37816 ([c++0x] Invalid handling of scoped enums defined at class scope)

	PR c++/37816
	* decl.c (build_enumerator): Don't add enumerators for a
	scoped enum to the enclosing class.

	PR c++/40639
	* decl.c (start_enum): Allow dependent underlying type.

	PR c++/40633
	* decl.c (finish_enum): Finish scope even in a template.

From-SVN: r149341
parent 72f90fde
2009-07-07 Jason Merrill <jason@redhat.com>
PR c++/37816
* decl.c (build_enumerator): Don't add enumerators for a
scoped enum to the enclosing class.
PR c++/40639
* decl.c (start_enum): Allow dependent underlying type.
PR c++/40633
* decl.c (finish_enum): Finish scope even in a template.
2009-07-07 Manuel López-Ibáñez <manu@gcc.gnu.org> 2009-07-07 Manuel López-Ibáñez <manu@gcc.gnu.org>
* init.c: Replace %J by an explicit location. Update all calls. * init.c: Replace %J by an explicit location. Update all calls.
......
...@@ -11049,7 +11049,7 @@ start_enum (tree name, tree underlying_type, bool scoped_enum_p) ...@@ -11049,7 +11049,7 @@ start_enum (tree name, tree underlying_type, bool scoped_enum_p)
TYPE_UNSIGNED (enumtype) = TYPE_UNSIGNED (underlying_type); TYPE_UNSIGNED (enumtype) = TYPE_UNSIGNED (underlying_type);
ENUM_UNDERLYING_TYPE (enumtype) = underlying_type; ENUM_UNDERLYING_TYPE (enumtype) = underlying_type;
} }
else else if (!dependent_type_p (underlying_type))
error ("underlying type %<%T%> of %<%T%> must be an integral type", error ("underlying type %<%T%> of %<%T%> must be an integral type",
underlying_type, enumtype); underlying_type, enumtype);
} }
...@@ -11095,6 +11095,8 @@ finish_enum (tree enumtype) ...@@ -11095,6 +11095,8 @@ finish_enum (tree enumtype)
TREE_TYPE (TREE_VALUE (values)) = enumtype; TREE_TYPE (TREE_VALUE (values)) = enumtype;
if (at_function_scope_p ()) if (at_function_scope_p ())
add_stmt (build_min (TAG_DEFN, enumtype)); add_stmt (build_min (TAG_DEFN, enumtype));
if (SCOPED_ENUM_P (enumtype))
finish_scope ();
return; return;
} }
...@@ -11410,7 +11412,7 @@ build_enumerator (tree name, tree value, tree enumtype) ...@@ -11410,7 +11412,7 @@ build_enumerator (tree name, tree value, tree enumtype)
TREE_READONLY (decl) = 1; TREE_READONLY (decl) = 1;
DECL_INITIAL (decl) = value; DECL_INITIAL (decl) = value;
if (context && context == current_class_type) if (context && context == current_class_type && !SCOPED_ENUM_P (enumtype))
/* In something like `struct S { enum E { i = 7 }; };' we put `i' /* In something like `struct S { enum E { i = 7 }; };' we put `i'
on the TYPE_FIELDS list for `S'. (That's so that you can say on the TYPE_FIELDS list for `S'. (That's so that you can say
things like `S::i' later.) */ things like `S::i' later.) */
......
2009-07-07 Jason Merrill <jason@redhat.com>
PR c++/37816
* g++.dg/cpp0x/enum7.C: New.
PR c++/37946
* g++.dg/cpp0x/enum6.C: New.
PR c++/40639
* g++.dg/cpp0x/enum5.C: New.
PR c++/40633
* g++.dg/cpp0x/enum4.C: New.
2009-07-07 Manuel López-Ibáñez <manu@gcc.gnu.org> 2009-07-07 Manuel López-Ibáñez <manu@gcc.gnu.org>
* gcc.dg/format/gcc_diag-1.c: Remove tests for %J. * gcc.dg/format/gcc_diag-1.c: Remove tests for %J.
......
// PR c++/40633
// { dg-options "-std=c++0x" }
template< typename T >
struct wrap {
enum class E { val };
};
// PR c++/40639
// { dg-options "-std=c++0x" }
template< typename T >
struct wrap {
enum E : T { val };
};
template< typename T >
struct dependant {
enum E : typename T::type { val };
};
template<typename T>
struct identity {
typedef T type;
};
wrap<int> x;
dependant<identity<int>> y;
// PR c++/37946
// { dg-options "-std=c++0x" }
enum class E : char
{
e1,
e2
};
inline E operator| (E a1, E a2)
{
char ret = static_cast<char> (a1)
| static_cast<char> (a2);
return static_cast<E>(ret);
}
// PR c++/37816
// { dg-options "-std=c++0x" }
class A
{
enum class Color { Red, Orange, Yellow, Green, Blue, Violet };
enum class Alert { Green, Yellow, Red };
static const Color x = Red; // { dg-error "" }
static const Color y = Color::Red;
static const Alert z = Alert::Red;
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment