public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/51242] New: Unable to use strongly typed enums as bit fields
@ 2011-11-20 19:55 volodya at netfolder dot ru
  2011-11-20 20:30 ` [Bug c++/51242] [C++11] " redi at gcc dot gnu.org
                   ` (28 more replies)
  0 siblings, 29 replies; 30+ messages in thread
From: volodya at netfolder dot ru @ 2011-11-20 19:55 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51242

             Bug #: 51242
           Summary: Unable to use strongly typed enums as bit fields
    Classification: Unclassified
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: volodya@netfolder.ru


In case of use strongly typed enumS as bit fields of structS in C++0x mode,
compiler says "bit-field 'smth' with non-integral type".

Though, the standard says "A bit-field shall have integral or enumeration type
(3.9.1)."


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [Bug c++/51242] [C++11] Unable to use strongly typed enums as bit fields
  2011-11-20 19:55 [Bug c++/51242] New: Unable to use strongly typed enums as bit fields volodya at netfolder dot ru
@ 2011-11-20 20:30 ` redi at gcc dot gnu.org
  2012-11-18 18:05 ` redi at gcc dot gnu.org
                   ` (27 subsequent siblings)
  28 siblings, 0 replies; 30+ messages in thread
From: redi at gcc dot gnu.org @ 2011-11-20 20:30 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51242

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid
                 CC|                            |jason at gcc dot gnu.org
            Summary|Unable to use strongly      |[C++11] Unable to use
                   |typed enums as bit fields   |strongly typed enums as bit
                   |                            |fields

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-11-20 20:26:58 UTC ---
In future please provide a complete testcase, as requested at
http://gcc.gnu.org/bugs

Testcase reduced from the one you posted to the gcc-help list:

enum class MyEnum { A = 1 };

struct MyClass
{
  MyEnum Field1 : 3;
};


Jason, the standard seems to say this should work, although I am rather
surprised - is that intended?


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [Bug c++/51242] [C++11] Unable to use strongly typed enums as bit fields
  2011-11-20 19:55 [Bug c++/51242] New: Unable to use strongly typed enums as bit fields volodya at netfolder dot ru
  2011-11-20 20:30 ` [Bug c++/51242] [C++11] " redi at gcc dot gnu.org
@ 2012-11-18 18:05 ` redi at gcc dot gnu.org
  2012-11-19  5:47 ` volodya at netfolder dot ru
                   ` (26 subsequent siblings)
  28 siblings, 0 replies; 30+ messages in thread
From: redi at gcc dot gnu.org @ 2012-11-18 18:05 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51242

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-11-18
     Ever Confirmed|0                           |1


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [Bug c++/51242] [C++11] Unable to use strongly typed enums as bit fields
  2011-11-20 19:55 [Bug c++/51242] New: Unable to use strongly typed enums as bit fields volodya at netfolder dot ru
  2011-11-20 20:30 ` [Bug c++/51242] [C++11] " redi at gcc dot gnu.org
  2012-11-18 18:05 ` redi at gcc dot gnu.org
@ 2012-11-19  5:47 ` volodya at netfolder dot ru
  2012-11-19  7:26 ` daniel.kruegler at googlemail dot com
                   ` (25 subsequent siblings)
  28 siblings, 0 replies; 30+ messages in thread
From: volodya at netfolder dot ru @ 2012-11-19  5:47 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51242

--- Comment #2 from Vladimir <volodya at netfolder dot ru> 2012-11-19 05:47:19 UTC ---
What does 'rejects-valid' keywords mean?
18.11.2012 22:05 пользователь "redi at gcc dot gnu.org" <
gcc-bugzilla@gcc.gnu.org> написал:

>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51242
>
> Jonathan Wakely <redi at gcc dot gnu.org> changed:
>
>            What    |Removed                     |Added
>
> ----------------------------------------------------------------------------
>              Status|UNCONFIRMED                 |NEW
>    Last reconfirmed|                            |2012-11-18
>      Ever Confirmed|0                           |1
>
> --
> Configure bugmail: http://gcc.gnu.org/bugzilla/userprefs.cgi?tab=email
> ------- You are receiving this mail because: -------
> You reported the bug.
>


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [Bug c++/51242] [C++11] Unable to use strongly typed enums as bit fields
  2011-11-20 19:55 [Bug c++/51242] New: Unable to use strongly typed enums as bit fields volodya at netfolder dot ru
                   ` (2 preceding siblings ...)
  2012-11-19  5:47 ` volodya at netfolder dot ru
@ 2012-11-19  7:26 ` daniel.kruegler at googlemail dot com
  2012-11-19  7:56 ` volodya at netfolder dot ru
                   ` (24 subsequent siblings)
  28 siblings, 0 replies; 30+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2012-11-19  7:26 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51242

--- Comment #3 from Daniel Krügler <daniel.kruegler at googlemail dot com> 2012-11-19 07:26:11 UTC ---
(In reply to comment #2)
> What does 'rejects-valid' keywords mean?
It means that the compiler rejects valid code, see

http://gcc.gnu.org/bugzilla/describekeywords.cgi


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [Bug c++/51242] [C++11] Unable to use strongly typed enums as bit fields
  2011-11-20 19:55 [Bug c++/51242] New: Unable to use strongly typed enums as bit fields volodya at netfolder dot ru
                   ` (3 preceding siblings ...)
  2012-11-19  7:26 ` daniel.kruegler at googlemail dot com
@ 2012-11-19  7:56 ` volodya at netfolder dot ru
  2012-11-19 11:47 ` redi at gcc dot gnu.org
                   ` (23 subsequent siblings)
  28 siblings, 0 replies; 30+ messages in thread
From: volodya at netfolder dot ru @ 2012-11-19  7:56 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51242

--- Comment #4 from Vladimir <volodya at netfolder dot ru> 2012-11-19 07:56:26 UTC ---
Sorry for stupid questions :)

Is this bug planned to be fixed in future?

Can I help in any way to do that?

2012/11/19 daniel.kruegler at googlemail dot com <gcc-bugzilla@gcc.gnu.org>:
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51242
>
> --- Comment #3 from Daniel Krügler <daniel.kruegler at googlemail dot com> 2012-11-19 07:26:11 UTC ---
> (In reply to comment #2)
>> What does 'rejects-valid' keywords mean?
> It means that the compiler rejects valid code, see
>
> http://gcc.gnu.org/bugzilla/describekeywords.cgi
>
> --
> Configure bugmail: http://gcc.gnu.org/bugzilla/userprefs.cgi?tab=email
> ------- You are receiving this mail because: -------
> You reported the bug.


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [Bug c++/51242] [C++11] Unable to use strongly typed enums as bit fields
  2011-11-20 19:55 [Bug c++/51242] New: Unable to use strongly typed enums as bit fields volodya at netfolder dot ru
                   ` (4 preceding siblings ...)
  2012-11-19  7:56 ` volodya at netfolder dot ru
@ 2012-11-19 11:47 ` redi at gcc dot gnu.org
  2012-11-19 11:52 ` redi at gcc dot gnu.org
                   ` (22 subsequent siblings)
  28 siblings, 0 replies; 30+ messages in thread
From: redi at gcc dot gnu.org @ 2012-11-19 11:47 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51242

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-11-19 11:47:20 UTC ---
(In reply to comment #4)
> Is this bug planned to be fixed in future?

Yes, of course. It's a bug.

> Can I help in any way to do that?

Sure, you could look in gcc/cp/*.c for the message
  "bit-field .* with non-integral type"
and see what conditions it depends on and why it disallows scoped enumeration
types.


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [Bug c++/51242] [C++11] Unable to use strongly typed enums as bit fields
  2011-11-20 19:55 [Bug c++/51242] New: Unable to use strongly typed enums as bit fields volodya at netfolder dot ru
                   ` (5 preceding siblings ...)
  2012-11-19 11:47 ` redi at gcc dot gnu.org
@ 2012-11-19 11:52 ` redi at gcc dot gnu.org
  2012-11-19 16:31 ` volodya at netfolder dot ru
                   ` (21 subsequent siblings)
  28 siblings, 0 replies; 30+ messages in thread
From: redi at gcc dot gnu.org @ 2012-11-19 11:52 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51242

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-11-19 11:52:38 UTC ---
The check is for an unscoped enumeration type which does seem intentional.

This change allows the example to compile:

--- cp/decl2.c.orig     2012-11-19 11:50:28.842443803 +0000
+++ cp/decl2.c  2012-11-19 11:46:08.445472115 +0000
@@ -1026,7 +1026,7 @@
   if (TREE_CODE (value) == VOID_TYPE)
     return void_type_node;

-  if (!INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (value))
+  if (!INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (value))
       && (POINTER_TYPE_P (value)
           || !dependent_type_p (TREE_TYPE (value))))
     {

It emits a warning though:

e.cc:5:19: warning: 'MyClass::Field1' is too small to hold all values of 'enum
class MyEnum' [enabled by default]


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [Bug c++/51242] [C++11] Unable to use strongly typed enums as bit fields
  2011-11-20 19:55 [Bug c++/51242] New: Unable to use strongly typed enums as bit fields volodya at netfolder dot ru
                   ` (6 preceding siblings ...)
  2012-11-19 11:52 ` redi at gcc dot gnu.org
@ 2012-11-19 16:31 ` volodya at netfolder dot ru
  2012-11-26 11:26 ` paolo.carlini at oracle dot com
                   ` (20 subsequent siblings)
  28 siblings, 0 replies; 30+ messages in thread
From: volodya at netfolder dot ru @ 2012-11-19 16:31 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51242

--- Comment #7 from Vladimir <volodya at netfolder dot ru> 2012-11-19 16:31:15 UTC ---
OK, I will see this message soon.

P.S. For now, I have to use Intel Compiller, which isn't good due limited
platform support (x86 and amd64).
---Исходное сообщение---
От: "redi at gcc dot gnu.org"
Отпр.:  19.11.2012, 15:47 
Кому: volodya@netfolder.ru
Тема: [Bug c++/51242] [C++11] Unable to use strongly typed enums as bit fields



http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51242

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-11-19
11:47:20 UTC ---
(In reply to comment #4)
> Is this bug planned to be fixed in future?

Yes, of course. It's a bug.

> Can I help in any way to do that?

Sure, you could look in gcc/cp/*.c for the message
  "bit-field .* with non-integral type"
and see what conditions it depends on and why it disallows scoped enumeration
types.


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [Bug c++/51242] [C++11] Unable to use strongly typed enums as bit fields
  2011-11-20 19:55 [Bug c++/51242] New: Unable to use strongly typed enums as bit fields volodya at netfolder dot ru
                   ` (7 preceding siblings ...)
  2012-11-19 16:31 ` volodya at netfolder dot ru
@ 2012-11-26 11:26 ` paolo.carlini at oracle dot com
  2012-11-26 11:32 ` paolo.carlini at oracle dot com
                   ` (19 subsequent siblings)
  28 siblings, 0 replies; 30+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-11-26 11:26 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51242

--- Comment #8 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-11-26 11:26:16 UTC ---
The warning noticed by Jon seems a latent issue unrelated to bitfields and due
to the fact to for scoped enums, the underlying type, if not explicitly
specified is if fixed to int type. Thus, in finish_enum_value_list,
fixed_underlying_type_p is true and the code "restricting" ENUM_UNDERLYING_TYPE
for the benefit of diagnostics doesn't run. It seems that it should run anyway,
when the underlying type is fixed but implicitly so.


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [Bug c++/51242] [C++11] Unable to use strongly typed enums as bit fields
  2011-11-20 19:55 [Bug c++/51242] New: Unable to use strongly typed enums as bit fields volodya at netfolder dot ru
                   ` (8 preceding siblings ...)
  2012-11-26 11:26 ` paolo.carlini at oracle dot com
@ 2012-11-26 11:32 ` paolo.carlini at oracle dot com
  2012-11-26 11:37 ` paolo.carlini at oracle dot com
                   ` (18 subsequent siblings)
  28 siblings, 0 replies; 30+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-11-26 11:32 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51242

--- Comment #9 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-11-26 11:32:15 UTC ---
Or maybe it should *always* run, if the point is diagnostics: after all even if
the type is fixed why not adding to its representation the information about
the actual range of values of the enumerators?!?


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [Bug c++/51242] [C++11] Unable to use strongly typed enums as bit fields
  2011-11-20 19:55 [Bug c++/51242] New: Unable to use strongly typed enums as bit fields volodya at netfolder dot ru
                   ` (9 preceding siblings ...)
  2012-11-26 11:32 ` paolo.carlini at oracle dot com
@ 2012-11-26 11:37 ` paolo.carlini at oracle dot com
  2012-11-26 11:47 ` redi at gcc dot gnu.org
                   ` (17 subsequent siblings)
  28 siblings, 0 replies; 30+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-11-26 11:37 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51242

--- Comment #10 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-11-26 11:36:56 UTC ---
For example, consider this variant of the PR53661 situation:

enum class Code {
  SUCCESS = 0
};

Code a;

short r[] = {a};

we currently produce a -Wnarrowing warning, which seems bogus to me, exactly
because we don't realize that actually the only enumerator has value zero.


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [Bug c++/51242] [C++11] Unable to use strongly typed enums as bit fields
  2011-11-20 19:55 [Bug c++/51242] New: Unable to use strongly typed enums as bit fields volodya at netfolder dot ru
                   ` (10 preceding siblings ...)
  2012-11-26 11:37 ` paolo.carlini at oracle dot com
@ 2012-11-26 11:47 ` redi at gcc dot gnu.org
  2012-11-26 11:51 ` redi at gcc dot gnu.org
                   ` (16 subsequent siblings)
  28 siblings, 0 replies; 30+ messages in thread
From: redi at gcc dot gnu.org @ 2012-11-26 11:47 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51242

--- Comment #11 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-11-26 11:46:46 UTC ---
That narrowing warning seems right to me, the enum variable could have a value
out of range of short:

  Code a = static_cast<Code>(SHRT_MAX+1);


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [Bug c++/51242] [C++11] Unable to use strongly typed enums as bit fields
  2011-11-20 19:55 [Bug c++/51242] New: Unable to use strongly typed enums as bit fields volodya at netfolder dot ru
                   ` (11 preceding siblings ...)
  2012-11-26 11:47 ` redi at gcc dot gnu.org
@ 2012-11-26 11:51 ` redi at gcc dot gnu.org
  2012-11-26 12:00 ` paolo.carlini at oracle dot com
                   ` (15 subsequent siblings)
  28 siblings, 0 replies; 30+ messages in thread
From: redi at gcc dot gnu.org @ 2012-11-26 11:51 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51242

--- Comment #12 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-11-26 11:50:43 UTC ---
The difference from PR 53661 is that the underlying type of a scoped
enumeration is fixed, so its values are the values of (in this case) int. In PR
53661 the underlying type is not fixed.


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [Bug c++/51242] [C++11] Unable to use strongly typed enums as bit fields
  2011-11-20 19:55 [Bug c++/51242] New: Unable to use strongly typed enums as bit fields volodya at netfolder dot ru
                   ` (12 preceding siblings ...)
  2012-11-26 11:51 ` redi at gcc dot gnu.org
@ 2012-11-26 12:00 ` paolo.carlini at oracle dot com
  2012-11-26 12:05 ` paolo.carlini at oracle dot com
                   ` (14 subsequent siblings)
  28 siblings, 0 replies; 30+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-11-26 12:00 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51242

--- Comment #13 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-11-26 12:00:17 UTC ---
But something still seems wrong to me. Why warning depending on whether 'class'
is there for the following:

enum /*class*/ Code {
  SUCCESS = 0
};

Code a;

short r[] = {a};


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [Bug c++/51242] [C++11] Unable to use strongly typed enums as bit fields
  2011-11-20 19:55 [Bug c++/51242] New: Unable to use strongly typed enums as bit fields volodya at netfolder dot ru
                   ` (13 preceding siblings ...)
  2012-11-26 12:00 ` paolo.carlini at oracle dot com
@ 2012-11-26 12:05 ` paolo.carlini at oracle dot com
  2012-11-26 12:12 ` paolo.carlini at oracle dot com
                   ` (13 subsequent siblings)
  28 siblings, 0 replies; 30+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-11-26 12:05 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51242

--- Comment #14 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-11-26 12:05:21 UTC ---
Anyway, the latent issue is of course with fixed underlying types: if in that
case we don't care about warning more, this issue is already fixed, very
likely. Even better ;)


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [Bug c++/51242] [C++11] Unable to use strongly typed enums as bit fields
  2011-11-20 19:55 [Bug c++/51242] New: Unable to use strongly typed enums as bit fields volodya at netfolder dot ru
                   ` (14 preceding siblings ...)
  2012-11-26 12:05 ` paolo.carlini at oracle dot com
@ 2012-11-26 12:12 ` paolo.carlini at oracle dot com
  2012-11-26 12:23 ` paolo.carlini at oracle dot com
                   ` (12 subsequent siblings)
  28 siblings, 0 replies; 30+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-11-26 12:12 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51242

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |paolo.carlini at oracle dot
                   |                            |com

--- Comment #15 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-11-26 12:12:12 UTC ---
To be clear, for:

enum class Code {
  SUCCESS = 0
};

Code a;// = static_cast<Code>(SHRT_MAX+1);

short r[] = {a};

we *error* out anyway, isn't that we are only emitting a warning and only when
we are assigning the SHRT_MAX + 1.


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [Bug c++/51242] [C++11] Unable to use strongly typed enums as bit fields
  2011-11-20 19:55 [Bug c++/51242] New: Unable to use strongly typed enums as bit fields volodya at netfolder dot ru
                   ` (15 preceding siblings ...)
  2012-11-26 12:12 ` paolo.carlini at oracle dot com
@ 2012-11-26 12:23 ` paolo.carlini at oracle dot com
  2012-11-26 12:43 ` redi at gcc dot gnu.org
                   ` (11 subsequent siblings)
  28 siblings, 0 replies; 30+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-11-26 12:23 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51242

--- Comment #16 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-11-26 12:22:49 UTC ---
And to further clarify wrt your specific Comment 11, Jon, for:

#include <limits.h>

enum Code {
  SUCCESS = 0
};

Code a = static_cast<Code>(SHRT_MAX + 1);

short r[] = {a};

we currently don't warn.


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [Bug c++/51242] [C++11] Unable to use strongly typed enums as bit fields
  2011-11-20 19:55 [Bug c++/51242] New: Unable to use strongly typed enums as bit fields volodya at netfolder dot ru
                   ` (16 preceding siblings ...)
  2012-11-26 12:23 ` paolo.carlini at oracle dot com
@ 2012-11-26 12:43 ` redi at gcc dot gnu.org
  2012-11-26 12:50 ` paolo.carlini at oracle dot com
                   ` (10 subsequent siblings)
  28 siblings, 0 replies; 30+ messages in thread
From: redi at gcc dot gnu.org @ 2012-11-26 12:43 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51242

--- Comment #17 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-11-26 12:43:37 UTC ---
(In reply to comment #15)
> we *error* out anyway, isn't that we are only emitting a warning and only when
> we are assigning the SHRT_MAX + 1.

But isn't the error because there's no implicit conversion from a scoped
enunmeration type to short?  That's just invalid.

And my point is that the narrowing warning is correct, because 'a' is not a
constant expression and its value could be out of the range
[SHRT_MIN,SHRT_MAX].

(In reply to comment #16)
> And to further clarify wrt your specific Comment 11, Jon, for:
> 
> #include <limits.h>
> 
> enum Code {
>   SUCCESS = 0
> };
> 
> Code a = static_cast<Code>(SHRT_MAX + 1);
> 
> short r[] = {a};
> 
> we currently don't warn.

Because the values of that unscoped enum type are [0,1] which always fit in
short.  With a scoped enumeration type the underlying type is fixed so the
values of the enumeration type are the values of the underlying type which are
[INT_MIN,INT_MAX].  But this seems unrelated to using scoped enums as bitfields
anyway.


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [Bug c++/51242] [C++11] Unable to use strongly typed enums as bit fields
  2011-11-20 19:55 [Bug c++/51242] New: Unable to use strongly typed enums as bit fields volodya at netfolder dot ru
                   ` (17 preceding siblings ...)
  2012-11-26 12:43 ` redi at gcc dot gnu.org
@ 2012-11-26 12:50 ` paolo.carlini at oracle dot com
  2012-11-26 12:56 ` redi at gcc dot gnu.org
                   ` (9 subsequent siblings)
  28 siblings, 0 replies; 30+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-11-26 12:50 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51242

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|paolo.carlini at oracle dot |
                   |com                         |

--- Comment #18 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-11-26 12:50:15 UTC ---
What can I say, if we are happy with these warnings when the underlying type is
fixed, then I think your patch is all there is to this issue, just regression
test it ;) It would be nice to double check that clang also warns, tough.


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [Bug c++/51242] [C++11] Unable to use strongly typed enums as bit fields
  2011-11-20 19:55 [Bug c++/51242] New: Unable to use strongly typed enums as bit fields volodya at netfolder dot ru
                   ` (18 preceding siblings ...)
  2012-11-26 12:50 ` paolo.carlini at oracle dot com
@ 2012-11-26 12:56 ` redi at gcc dot gnu.org
  2012-11-26 13:00 ` paolo.carlini at oracle dot com
                   ` (8 subsequent siblings)
  28 siblings, 0 replies; 30+ messages in thread
From: redi at gcc dot gnu.org @ 2012-11-26 12:56 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51242

--- Comment #19 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-11-26 12:56:34 UTC ---
Clang doesn't warn for the code in comment 1


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [Bug c++/51242] [C++11] Unable to use strongly typed enums as bit fields
  2011-11-20 19:55 [Bug c++/51242] New: Unable to use strongly typed enums as bit fields volodya at netfolder dot ru
                   ` (19 preceding siblings ...)
  2012-11-26 12:56 ` redi at gcc dot gnu.org
@ 2012-11-26 13:00 ` paolo.carlini at oracle dot com
  2012-11-26 13:28 ` paolo.carlini at oracle dot com
                   ` (7 subsequent siblings)
  28 siblings, 0 replies; 30+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-11-26 13:00 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51242

--- Comment #20 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-11-26 13:00:08 UTC ---
Well, then we should double check whether it warns at all when bitfields are
not involved, because I don't see anything bitfield-specific about the warning.
Maybe it just warns less for these narrowing issues with scoped and unscoped
enums?


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [Bug c++/51242] [C++11] Unable to use strongly typed enums as bit fields
  2011-11-20 19:55 [Bug c++/51242] New: Unable to use strongly typed enums as bit fields volodya at netfolder dot ru
                   ` (20 preceding siblings ...)
  2012-11-26 13:00 ` paolo.carlini at oracle dot com
@ 2012-11-26 13:28 ` paolo.carlini at oracle dot com
  2012-11-26 13:39 ` paolo.carlini at oracle dot com
                   ` (6 subsequent siblings)
  28 siblings, 0 replies; 30+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-11-26 13:28 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51242

--- Comment #21 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-11-26 13:27:45 UTC ---
Uhm, actually, when the underlying type is unscoped and we already accept the
code, we warn exactly in the same way. I'm not sure if this is already clear to
everybody, definitely wasn't clear to me, sorry if I misled you Jon or somebody
else into thinking that the possible issues having to do with -Wnarrowing were
important for this issue, I understand now they are not:

enum MyEnum { A1 = 1, A2 = 2 };

struct MyClass
{
  MyEnum Field1 : 1;
};

Thus, it really seems the fix for this issue boils down to loosening the check
in grokbitfield and that's it.


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [Bug c++/51242] [C++11] Unable to use strongly typed enums as bit fields
  2011-11-20 19:55 [Bug c++/51242] New: Unable to use strongly typed enums as bit fields volodya at netfolder dot ru
                   ` (21 preceding siblings ...)
  2012-11-26 13:28 ` paolo.carlini at oracle dot com
@ 2012-11-26 13:39 ` paolo.carlini at oracle dot com
  2012-11-26 14:00 ` paolo.carlini at oracle dot com
                   ` (5 subsequent siblings)
  28 siblings, 0 replies; 30+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-11-26 13:39 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51242

--- Comment #22 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-11-26 13:39:17 UTC ---
I mean, with the grokbitfield tweak we obtain a behavior for Comment #1 which
in terms of warnings it's just a variant of Comment #13: if we already decided
that it's fine to warn when the underlying type is fixed for Comment #13, we
have in my opinion to consistently warn for Comment #1.


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [Bug c++/51242] [C++11] Unable to use strongly typed enums as bit fields
  2011-11-20 19:55 [Bug c++/51242] New: Unable to use strongly typed enums as bit fields volodya at netfolder dot ru
                   ` (22 preceding siblings ...)
  2012-11-26 13:39 ` paolo.carlini at oracle dot com
@ 2012-11-26 14:00 ` paolo.carlini at oracle dot com
  2012-11-26 14:40 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  28 siblings, 0 replies; 30+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-11-26 14:00 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51242

--- Comment #23 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-11-26 14:00:37 UTC ---
Patchlet in Comment #6 passes testing for me.

As I tried clumsily to explain, I don't think it's consistent to avoid the
warning for Comment #1 if we warn for Comment #13 scoped, but it's also
annoying that the "too small to hold all values" warning it's enable by
default, thus can't be suppresed: maybe we could give it a name (if we don't
want to re-open the discussion about -Wnarrowing and the range of the
underlying type when the type is fixed ;)


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [Bug c++/51242] [C++11] Unable to use strongly typed enums as bit fields
  2011-11-20 19:55 [Bug c++/51242] New: Unable to use strongly typed enums as bit fields volodya at netfolder dot ru
                   ` (23 preceding siblings ...)
  2012-11-26 14:00 ` paolo.carlini at oracle dot com
@ 2012-11-26 14:40 ` redi at gcc dot gnu.org
  2013-02-16  1:07 ` paolo at gcc dot gnu.org
                   ` (3 subsequent siblings)
  28 siblings, 0 replies; 30+ messages in thread
From: redi at gcc dot gnu.org @ 2012-11-26 14:40 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51242

--- Comment #24 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-11-26 14:40:20 UTC ---
I think naming the warning would make sense, so it can be disabled by people
who want to use scoped enums with bit-fields


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [Bug c++/51242] [C++11] Unable to use strongly typed enums as bit fields
  2011-11-20 19:55 [Bug c++/51242] New: Unable to use strongly typed enums as bit fields volodya at netfolder dot ru
                   ` (24 preceding siblings ...)
  2012-11-26 14:40 ` redi at gcc dot gnu.org
@ 2013-02-16  1:07 ` paolo at gcc dot gnu.org
  2013-02-27 10:33 ` paolo.carlini at oracle dot com
                   ` (2 subsequent siblings)
  28 siblings, 0 replies; 30+ messages in thread
From: paolo at gcc dot gnu.org @ 2013-02-16  1:07 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51242

--- Comment #25 from paolo at gcc dot gnu.org <paolo at gcc dot gnu.org> 2013-02-16 01:07:16 UTC ---
Author: paolo
Date: Sat Feb 16 01:07:11 2013
New Revision: 196100

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=196100
Log:
/cp
2013-02-15  Jonathan Wakely  <jwakely.gcc@gmail.com>
        Paolo Carlini  <paolo.carlini@oracle.com>

    PR c++/51242
    * decl2.c (grokbitfield): Allow scoped enumeration types.

/testsuite
2013-02-15  Jonathan Wakely  <jwakely.gcc@gmail.com>
        Paolo Carlini  <paolo.carlini@oracle.com>

    PR c++/51242
    * g++.dg/cpp0x/enum23.C: New.


Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/enum23.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/decl2.c
    trunk/gcc/testsuite/ChangeLog


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [Bug c++/51242] [C++11] Unable to use strongly typed enums as bit fields
  2011-11-20 19:55 [Bug c++/51242] New: Unable to use strongly typed enums as bit fields volodya at netfolder dot ru
                   ` (25 preceding siblings ...)
  2013-02-16  1:07 ` paolo at gcc dot gnu.org
@ 2013-02-27 10:33 ` paolo.carlini at oracle dot com
  2020-11-08 18:06 ` barry.revzin at gmail dot com
  2020-11-09 10:01 ` redi at gcc dot gnu.org
  28 siblings, 0 replies; 30+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-02-27 10:33 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51242

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|jason at gcc dot gnu.org    |

--- Comment #26 from Paolo Carlini <paolo.carlini at oracle dot com> 2013-02-27 10:32:49 UTC ---
Note: I'm keeping this open because we may want to do something about the
warning:

  http://gcc.gnu.org/ml/gcc-patches/2013-02/msg00786.html


^ permalink raw reply	[flat|nested] 30+ messages in thread

* [Bug c++/51242] [C++11] Unable to use strongly typed enums as bit fields
  2011-11-20 19:55 [Bug c++/51242] New: Unable to use strongly typed enums as bit fields volodya at netfolder dot ru
                   ` (26 preceding siblings ...)
  2013-02-27 10:33 ` paolo.carlini at oracle dot com
@ 2020-11-08 18:06 ` barry.revzin at gmail dot com
  2020-11-09 10:01 ` redi at gcc dot gnu.org
  28 siblings, 0 replies; 30+ messages in thread
From: barry.revzin at gmail dot com @ 2020-11-08 18:06 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51242

Barry Revzin <barry.revzin at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |barry.revzin at gmail dot com

--- Comment #31 from Barry Revzin <barry.revzin at gmail dot com> ---
Apparently this was fixed in 9.3?

enum class Color { Red, Green, Blue };

struct X {
    Color c : 2;
};

auto x = X{.c=Color::Red};

warns on 9.2, but not anymore on 9.3 or 10.

^ permalink raw reply	[flat|nested] 30+ messages in thread

* [Bug c++/51242] [C++11] Unable to use strongly typed enums as bit fields
  2011-11-20 19:55 [Bug c++/51242] New: Unable to use strongly typed enums as bit fields volodya at netfolder dot ru
                   ` (27 preceding siblings ...)
  2020-11-08 18:06 ` barry.revzin at gmail dot com
@ 2020-11-09 10:01 ` redi at gcc dot gnu.org
  28 siblings, 0 replies; 30+ messages in thread
From: redi at gcc dot gnu.org @ 2020-11-09 10:01 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51242

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED
   Target Milestone|---                         |9.2

--- Comment #32 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Barry Revzin from comment #31)
> warns on 9.2, but not anymore on 9.3 or 10.

Changed by r278736 for PR c++/61414

In comment 26 Paolo said this was kept open because of the warning that Jakub
fixed, so I'm closing this.

^ permalink raw reply	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2020-11-09 10:01 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-20 19:55 [Bug c++/51242] New: Unable to use strongly typed enums as bit fields volodya at netfolder dot ru
2011-11-20 20:30 ` [Bug c++/51242] [C++11] " redi at gcc dot gnu.org
2012-11-18 18:05 ` redi at gcc dot gnu.org
2012-11-19  5:47 ` volodya at netfolder dot ru
2012-11-19  7:26 ` daniel.kruegler at googlemail dot com
2012-11-19  7:56 ` volodya at netfolder dot ru
2012-11-19 11:47 ` redi at gcc dot gnu.org
2012-11-19 11:52 ` redi at gcc dot gnu.org
2012-11-19 16:31 ` volodya at netfolder dot ru
2012-11-26 11:26 ` paolo.carlini at oracle dot com
2012-11-26 11:32 ` paolo.carlini at oracle dot com
2012-11-26 11:37 ` paolo.carlini at oracle dot com
2012-11-26 11:47 ` redi at gcc dot gnu.org
2012-11-26 11:51 ` redi at gcc dot gnu.org
2012-11-26 12:00 ` paolo.carlini at oracle dot com
2012-11-26 12:05 ` paolo.carlini at oracle dot com
2012-11-26 12:12 ` paolo.carlini at oracle dot com
2012-11-26 12:23 ` paolo.carlini at oracle dot com
2012-11-26 12:43 ` redi at gcc dot gnu.org
2012-11-26 12:50 ` paolo.carlini at oracle dot com
2012-11-26 12:56 ` redi at gcc dot gnu.org
2012-11-26 13:00 ` paolo.carlini at oracle dot com
2012-11-26 13:28 ` paolo.carlini at oracle dot com
2012-11-26 13:39 ` paolo.carlini at oracle dot com
2012-11-26 14:00 ` paolo.carlini at oracle dot com
2012-11-26 14:40 ` redi at gcc dot gnu.org
2013-02-16  1:07 ` paolo at gcc dot gnu.org
2013-02-27 10:33 ` paolo.carlini at oracle dot com
2020-11-08 18:06 ` barry.revzin at gmail dot com
2020-11-09 10:01 ` redi at gcc dot gnu.org

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).