* [C++ Patch] Fix 66243, silent cast of scoped enum
@ 2015-05-25 1:26 Nathan Sidwell
2015-05-25 19:52 ` Jason Merrill
0 siblings, 1 reply; 4+ messages in thread
From: Nathan Sidwell @ 2015-05-25 1:26 UTC (permalink / raw)
To: GCC Patches; +Cc: Jason Merrill
[-- Attachment #1: Type: text/plain, Size: 205 bytes --]
This is a pretty obvious patch. We were permitting a scoped enum initializer of
an another enum to silently decay to int. That's not right, only unscoped enums
have that privilege.
committed.
nathan
[-- Attachment #2: 66243.patch --]
[-- Type: text/x-patch, Size: 1139 bytes --]
2015-05-24 Nathan Sidwell <nathan@acm.org>
cp/
PR c++/66243
* decl.c (build_enumerator): Don't silently convert scoped enums.
testsuite/
PR c++/66243
* g++.dg/cpp0x/pr66243.C: New.
Index: cp/decl.c
===================================================================
--- cp/decl.c (revision 223613)
+++ cp/decl.c (working copy)
@@ -13097,7 +13097,8 @@ build_enumerator (tree name, tree value,
if (tmp_value)
value = tmp_value;
}
- else if (! INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (value)))
+ else if (! INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P
+ (TREE_TYPE (value)))
value = perform_implicit_conversion_flags
(ENUM_UNDERLYING_TYPE (enumtype), value, tf_warning_or_error,
LOOKUP_IMPLICIT | LOOKUP_NO_NARROWING);
Index: testsuite/g++.dg/cpp0x/pr66243.C
===================================================================
--- testsuite/g++.dg/cpp0x/pr66243.C (revision 0)
+++ testsuite/g++.dg/cpp0x/pr66243.C (working copy)
@@ -0,0 +1,12 @@
+// { dg-do compile { target c++11 } }
+
+enum class A
+{
+ X
+};
+
+enum class B
+{
+ X = A::X // { dg-error "could not convert" }
+};
+
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [C++ Patch] Fix 66243, silent cast of scoped enum
2015-05-25 1:26 [C++ Patch] Fix 66243, silent cast of scoped enum Nathan Sidwell
@ 2015-05-25 19:52 ` Jason Merrill
2015-05-25 20:29 ` Nathan Sidwell
0 siblings, 1 reply; 4+ messages in thread
From: Jason Merrill @ 2015-05-25 19:52 UTC (permalink / raw)
To: Nathan Sidwell, GCC Patches
On 05/24/2015 07:20 PM, Nathan Sidwell wrote:
> - else if (! INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (value)))
> + else if (! INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P
> + (TREE_TYPE (value)))
> value = perform_implicit_conversion_flags
> (ENUM_UNDERLYING_TYPE (enumtype), value, tf_warning_or_error,
> LOOKUP_IMPLICIT | LOOKUP_NO_NARROWING);
The change is fine, but I wonder why perform_implicit_conversion_flags
was succeeding? I would think it should fail.
Jason
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [C++ Patch] Fix 66243, silent cast of scoped enum
2015-05-25 19:52 ` Jason Merrill
@ 2015-05-25 20:29 ` Nathan Sidwell
2015-05-26 7:49 ` Jason Merrill
0 siblings, 1 reply; 4+ messages in thread
From: Nathan Sidwell @ 2015-05-25 20:29 UTC (permalink / raw)
To: Jason Merrill, GCC Patches
On 05/25/15 15:43, Jason Merrill wrote:
> On 05/24/2015 07:20 PM, Nathan Sidwell wrote:
>> - else if (! INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (value)))
>> + else if (! INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P
>> + (TREE_TYPE (value)))
>> value = perform_implicit_conversion_flags
>> (ENUM_UNDERLYING_TYPE (enumtype), value, tf_warning_or_error,
>> LOOKUP_IMPLICIT | LOOKUP_NO_NARROWING);
>
> The change is fine, but I wonder why perform_implicit_conversion_flags was
> succeeding? I would think it should fail.
It wasn't being executed. The if condition is if *NOT* integral-or-enum. The
patch changes the check such that p_i_c_f is now executed for scoped enums --
and emits an appropriate error.
nathan
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [C++ Patch] Fix 66243, silent cast of scoped enum
2015-05-25 20:29 ` Nathan Sidwell
@ 2015-05-26 7:49 ` Jason Merrill
0 siblings, 0 replies; 4+ messages in thread
From: Jason Merrill @ 2015-05-26 7:49 UTC (permalink / raw)
To: Nathan Sidwell, GCC Patches
On 05/25/2015 04:14 PM, Nathan Sidwell wrote:
> On 05/25/15 15:43, Jason Merrill wrote:
>> On 05/24/2015 07:20 PM, Nathan Sidwell wrote:
>>> - else if (! INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (value)))
>>> + else if (! INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P
>>> + (TREE_TYPE (value)))
>>> value = perform_implicit_conversion_flags
>>> (ENUM_UNDERLYING_TYPE (enumtype), value, tf_warning_or_error,
>>> LOOKUP_IMPLICIT | LOOKUP_NO_NARROWING);
>>
>> The change is fine, but I wonder why perform_implicit_conversion_flags
>> was
>> succeeding? I would think it should fail.
>
> It wasn't being executed. The if condition is if *NOT*
> integral-or-enum. The patch changes the check such that p_i_c_f is now
> executed for scoped enums -- and emits an appropriate error.
Ah, of course, thanks.
Jason
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-05-26 1:10 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-25 1:26 [C++ Patch] Fix 66243, silent cast of scoped enum Nathan Sidwell
2015-05-25 19:52 ` Jason Merrill
2015-05-25 20:29 ` Nathan Sidwell
2015-05-26 7:49 ` Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).