Message ID | 22f2aee0-29d3-1c18-3871-291f08be4984@oracle.com |
---|---|
State | New |
Headers | show |
On Tue, Jul 12, 2016 at 10:30 AM, Paolo Carlini <paolo.carlini@oracle.com> wrote: > On 30/06/2016 19:49, Jason Merrill wrote: >> I think we should check the type before calling cxx_constant_value. >> > Ok, I got the point. I'm not sure however how far we want to go with this > and which kind of consistency we want to achieve (vs error messages issued > in other similar circumstances). The below certainly passes testing on > x86_64-linux. I meant the actual type of the expression: that is, check INTEGRAL_OR_ENUMERATION_TYPE_P before calling cxx_constant_value. Jason
Index: cp/decl.c =================================================================== --- cp/decl.c (revision 238239) +++ cp/decl.c (working copy) @@ -13585,7 +13585,9 @@ build_enumerator (tree name, tree value, tree enum if (value != NULL_TREE) { - value = cxx_constant_value (value); + if (TREE_CODE (value) != COMPONENT_REF + || !is_overloaded_fn (value)) + value = cxx_constant_value (value); if (TREE_CODE (value) != INTEGER_CST || ! INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (value))) Index: testsuite/g++.dg/cpp0x/pr71665.C =================================================================== --- testsuite/g++.dg/cpp0x/pr71665.C (revision 0) +++ testsuite/g++.dg/cpp0x/pr71665.C (working copy) @@ -0,0 +1,8 @@ +// PR c++/71665 +// { dg-do compile { target c++11 } } + +class A +{ + int f (); + enum { a = f }; // { dg-error "enumerator value" } +};