@@ -4022,7 +4022,13 @@ maybe_constant_value (tree t, tree decl)
if (!ret)
{
ret = maybe_constant_value_1 (t, decl);
- cv_cache.put (t, ret);
+ /* While parsing an enumerator-list, the type of each enumerator
+ is the type of its initializing value. After the parsing has
+ been done, it will have the type of its enumeration. And this
+ discrepancy could get us in trouble later. */
+ if (TREE_CODE (t) != CONST_DECL
+ || TREE_TYPE (t) == DECL_CONTEXT (t))
+ cv_cache.put (t, ret);
}
return ret;
}
@@ -0,0 +1,14 @@
+// PR c++/68586
+// { dg-do compile { target c++11 } }
+
+enum E { x = 1, y = x << 1 };
+template<E> struct A {};
+A<x> a;
+
+enum E2 : int { x2 = 1, y2 = x2 << 1 };
+template<E2> struct A2 {};
+A2<x2> a2;
+
+enum class E3 { x3 = 1, y3 = x3 << 1 };
+template<E3> struct A3 {};
+A3<E3::x3> a3;