public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/102804] New: template matching fails w/ false ambiguity on ternary expressions with enums
@ 2021-10-17 22:09 rudick at gmail dot com
  2021-10-17 22:18 ` [Bug c++/102804] template matching fails w/ false ambiguity on ternary expressions with enums class defined with unsigned int32_t pinskia at gcc dot gnu.org
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: rudick at gmail dot com @ 2021-10-17 22:09 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 102804
           Summary: template matching fails w/ false ambiguity on ternary
                    expressions with enums
           Product: gcc
           Version: 11.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rudick at gmail dot com
  Target Milestone: ---

E.g. w/ -std=c++11

#include <iostream>
int main() {
  enum: unsigned int32_t { FOO, BAR } foobar = FOO;
  std::cout << ((time(nullptr) % 2) ? foobar : 13) << std::endl;
}

The initial error is:

error: ambiguous overload for ‘operator<<’ (operand types are ‘std::ostream’
{aka ‘std::basic_ostream<char>’} and ‘unsigned int’)

in gcc9.2 & gcc 11.2.0

gcc7 happily compiles the code.

with -Wextra, all 3 versions warn:

error: enumerated and non-enumerated type in conditional expression

Version: 11.2.0

system: CentOS Linux 7.7.1908 on Intel Xeon

command: g++ -Wall -Wextra -std=c++11 20211017-bug.cpp

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

* [Bug c++/102804] template matching fails w/ false ambiguity on ternary expressions with enums class defined with unsigned int32_t
  2021-10-17 22:09 [Bug c++/102804] New: template matching fails w/ false ambiguity on ternary expressions with enums rudick at gmail dot com
@ 2021-10-17 22:18 ` pinskia at gcc dot gnu.org
  2021-10-18  0:04 ` [Bug c++/102804] template matching fails w/ false ambiguity on ternary expressions with enums class defined with unsigned typdef redi at gcc dot gnu.org
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-10-17 22:18 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|template matching fails w/  |template matching fails w/
                   |false ambiguity on ternary  |false ambiguity on ternary
                   |expressions with enums      |expressions with enums
                   |                            |class defined with unsigned
                   |                            |int32_t

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Hmm:
<source>:4:9: error: 'unsigned' specified with 'int32_t' {aka 'int'}
[-Wpedantic]
    4 |   enum: unsigned int32_t { FOO, BAR } foobar = FOO;
      |         ^~~~~~~~


Looks like this is the cause of the problem, Changing it to unsigned or
uint32_t and the error goes away ...

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

* [Bug c++/102804] template matching fails w/ false ambiguity on ternary expressions with enums class defined with unsigned typdef
  2021-10-17 22:09 [Bug c++/102804] New: template matching fails w/ false ambiguity on ternary expressions with enums rudick at gmail dot com
  2021-10-17 22:18 ` [Bug c++/102804] template matching fails w/ false ambiguity on ternary expressions with enums class defined with unsigned int32_t pinskia at gcc dot gnu.org
@ 2021-10-18  0:04 ` redi at gcc dot gnu.org
  2021-10-18  0:16 ` redi at gcc dot gnu.org
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: redi at gcc dot gnu.org @ 2021-10-18  0:04 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
unsigned int32_t is invalid. You cannot use unsigned (or short or long) with a
typedef, only with 'int'.

GCC was changed to diagnose that fairly recently, which is probably why the
behaviour changed since GCC 7.

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

* [Bug c++/102804] template matching fails w/ false ambiguity on ternary expressions with enums class defined with unsigned typdef
  2021-10-17 22:09 [Bug c++/102804] New: template matching fails w/ false ambiguity on ternary expressions with enums rudick at gmail dot com
  2021-10-17 22:18 ` [Bug c++/102804] template matching fails w/ false ambiguity on ternary expressions with enums class defined with unsigned int32_t pinskia at gcc dot gnu.org
  2021-10-18  0:04 ` [Bug c++/102804] template matching fails w/ false ambiguity on ternary expressions with enums class defined with unsigned typdef redi at gcc dot gnu.org
@ 2021-10-18  0:16 ` redi at gcc dot gnu.org
  2021-10-18  6:51 ` rguenth at gcc dot gnu.org
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: redi at gcc dot gnu.org @ 2021-10-18  0:16 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I think it was pr 84701

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

* [Bug c++/102804] template matching fails w/ false ambiguity on ternary expressions with enums class defined with unsigned typdef
  2021-10-17 22:09 [Bug c++/102804] New: template matching fails w/ false ambiguity on ternary expressions with enums rudick at gmail dot com
                   ` (2 preceding siblings ...)
  2021-10-18  0:16 ` redi at gcc dot gnu.org
@ 2021-10-18  6:51 ` rguenth at gcc dot gnu.org
  2021-10-18 16:23 ` rudick at gmail dot com
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-10-18  6:51 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
Thus invalid.

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

* [Bug c++/102804] template matching fails w/ false ambiguity on ternary expressions with enums class defined with unsigned typdef
  2021-10-17 22:09 [Bug c++/102804] New: template matching fails w/ false ambiguity on ternary expressions with enums rudick at gmail dot com
                   ` (3 preceding siblings ...)
  2021-10-18  6:51 ` rguenth at gcc dot gnu.org
@ 2021-10-18 16:23 ` rudick at gmail dot com
  2021-10-18 16:37 ` [Bug c++/102804] [9/10/11/12 Regression] template matching fails w/ false ambiguity on ternary expressions with enums class defined with unsigned typedef redi at gcc dot gnu.org
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: rudick at gmail dot com @ 2021-10-18 16:23 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Todd Rudick <rudick at gmail dot com> ---
Richard, is there a way to represent the part of this that is a bug? 
Presumably accepting the construct but having it break template specialization
with an error that can be arbitrarily disconnected from the definition is not a
desired behavior. In the production code that I eventually isolated this from,
there is in fact no reference at all to the header that contained the enum.

Also, it seems likely that the compiler state is bad at that point (?), as the
error message indicates an 'unsigned int' ambiguity that doesn't actually
exist.

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

* [Bug c++/102804] [9/10/11/12 Regression] template matching fails w/ false ambiguity on ternary expressions with enums class defined with unsigned typedef
  2021-10-17 22:09 [Bug c++/102804] New: template matching fails w/ false ambiguity on ternary expressions with enums rudick at gmail dot com
                   ` (4 preceding siblings ...)
  2021-10-18 16:23 ` rudick at gmail dot com
@ 2021-10-18 16:37 ` redi at gcc dot gnu.org
  2021-10-18 16:43 ` redi at gcc dot gnu.org
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: redi at gcc dot gnu.org @ 2021-10-18 16:37 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |NEW
            Summary|template matching fails w/  |[9/10/11/12 Regression]
                   |false ambiguity on ternary  |template matching fails w/
                   |expressions with enums      |false ambiguity on ternary
                   |class defined with unsigned |expressions with enums
                   |typdef                      |class defined with unsigned
                   |                            |typedef
                 CC|                            |mukesh.kapoor at oracle dot com
         Resolution|INVALID                     |---
      Known to work|                            |7.4.0
   Last reconfirmed|                            |2021-10-18
     Ever confirmed|0                           |1
           Keywords|                            |rejects-valid
      Known to fail|                            |8.1.0

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This is a bug, we should either reject 'unsigned int32_t' immediately (which we
only do with -pedantic-errors) or we should accept it and treat it consistently
as unsigned int.

Reduced:

enum: unsigned int32_t { FOO, BAR } foobar = FOO;
int f(int);
int f(unsigned);
auto x = f(1 ? foobar : 13);


With r254043 we just have a pedwarn:

102804.C:2:16: warning: long, short, signed or unsigned used invalidly for
'type name' [-Wpedantic]
 enum: unsigned int32_t { FOO, BAR } foobar = FOO;
                ^~~~~~~

With r254046 we get the error:

102804.C:2:16: warning: long, short, signed or unsigned used invalidly for
'type name' [-Wpedantic]
 enum: unsigned int32_t { FOO, BAR } foobar = FOO;
                ^~~~~~~
102804.C:5:27: error: call of overloaded 'f(unsigned int)' is ambiguous
 auto x = f(1 ? foobar : 13);
                           ^
102804.C:3:5: note: candidate: 'int f(int)'
 int f(int);
     ^
102804.C:4:5: note: candidate: 'int f(unsigned int)'
 int f(unsigned);
     ^


    re PR c++/82307 (unscoped enum-base incorrect cast)

    /cp
    2017-10-24  Mukesh Kapoor  <mukesh.kapoor@oracle.com>
                Paolo Carlini  <paolo.carlini@oracle.com>

            PR c++/82307
            * cvt.c (type_promotes_to): Implement C++17, 7.6/4, about unscoped
            enumeration type whose underlying type is fixed.


So it was actually caused by fixing the promotion rules for enums (PR 82307),
not by the handling of 'unsigned' applied to a typedef.

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

* [Bug c++/102804] [9/10/11/12 Regression] template matching fails w/ false ambiguity on ternary expressions with enums class defined with unsigned typedef
  2021-10-17 22:09 [Bug c++/102804] New: template matching fails w/ false ambiguity on ternary expressions with enums rudick at gmail dot com
                   ` (5 preceding siblings ...)
  2021-10-18 16:37 ` [Bug c++/102804] [9/10/11/12 Regression] template matching fails w/ false ambiguity on ternary expressions with enums class defined with unsigned typedef redi at gcc dot gnu.org
@ 2021-10-18 16:43 ` redi at gcc dot gnu.org
  2021-10-18 21:08 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: redi at gcc dot gnu.org @ 2021-10-18 16:43 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Oops, sorry the reduced example was missing the first line.

Fixed, and further reduced:

using int32_t = int;
enum: unsigned int32_t { foo };
int f(int);
int f(unsigned);
auto x = f(1 ? foo : 1);

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

* [Bug c++/102804] [9/10/11/12 Regression] template matching fails w/ false ambiguity on ternary expressions with enums class defined with unsigned typedef
  2021-10-17 22:09 [Bug c++/102804] New: template matching fails w/ false ambiguity on ternary expressions with enums rudick at gmail dot com
                   ` (6 preceding siblings ...)
  2021-10-18 16:43 ` redi at gcc dot gnu.org
@ 2021-10-18 21:08 ` pinskia at gcc dot gnu.org
  2021-11-05 13:56 ` rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-10-18 21:08 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pinskia at gcc dot gnu.org
   Target Milestone|---                         |9.5
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=82307

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

* [Bug c++/102804] [9/10/11/12 Regression] template matching fails w/ false ambiguity on ternary expressions with enums class defined with unsigned typedef
  2021-10-17 22:09 [Bug c++/102804] New: template matching fails w/ false ambiguity on ternary expressions with enums rudick at gmail dot com
                   ` (7 preceding siblings ...)
  2021-10-18 21:08 ` pinskia at gcc dot gnu.org
@ 2021-11-05 13:56 ` rguenth at gcc dot gnu.org
  2022-04-15  1:55 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-11-05 13:56 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2

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

* [Bug c++/102804] [9/10/11/12 Regression] template matching fails w/ false ambiguity on ternary expressions with enums class defined with unsigned typedef
  2021-10-17 22:09 [Bug c++/102804] New: template matching fails w/ false ambiguity on ternary expressions with enums rudick at gmail dot com
                   ` (8 preceding siblings ...)
  2021-11-05 13:56 ` rguenth at gcc dot gnu.org
@ 2022-04-15  1:55 ` cvs-commit at gcc dot gnu.org
  2022-05-27  9:46 ` [Bug c++/102804] [10/11 " rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-04-15  1:55 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jason Merrill <jason@gcc.gnu.org>:

https://gcc.gnu.org/g:e580f81d22d61153564959f08d9a6d3bcc7fd386

commit r12-8173-ge580f81d22d61153564959f08d9a6d3bcc7fd386
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Apr 14 17:49:47 2022 -0400

    c++: unsigned int32_t enum promotion [PR102804]

    There's been an extension for a long time to allow applying 'unsigned' to
an
    int typedef, but that was confusing the integer promotion code.  Fixed by
    forgetting about the typedef in that case.

    I'm going to make this an unconditional pedwarn in stage 1.

            PR c++/102804

    gcc/cp/ChangeLog:

            * decl.cc (grokdeclarator): Drop typedef used with 'unsigned'.

    gcc/testsuite/ChangeLog:

            * g++.dg/ext/unsigned-typedef1.C: New test.

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

* [Bug c++/102804] [10/11 Regression] template matching fails w/ false ambiguity on ternary expressions with enums class defined with unsigned typedef
  2021-10-17 22:09 [Bug c++/102804] New: template matching fails w/ false ambiguity on ternary expressions with enums rudick at gmail dot com
                   ` (9 preceding siblings ...)
  2022-04-15  1:55 ` cvs-commit at gcc dot gnu.org
@ 2022-05-27  9:46 ` rguenth at gcc dot gnu.org
  2022-06-28 10:46 ` jakub at gcc dot gnu.org
  2023-07-07 10:41 ` [Bug c++/102804] [11 " rguenth at gcc dot gnu.org
  12 siblings, 0 replies; 14+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-05-27  9:46 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|9.5                         |10.4

--- Comment #9 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 9 branch is being closed

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

* [Bug c++/102804] [10/11 Regression] template matching fails w/ false ambiguity on ternary expressions with enums class defined with unsigned typedef
  2021-10-17 22:09 [Bug c++/102804] New: template matching fails w/ false ambiguity on ternary expressions with enums rudick at gmail dot com
                   ` (10 preceding siblings ...)
  2022-05-27  9:46 ` [Bug c++/102804] [10/11 " rguenth at gcc dot gnu.org
@ 2022-06-28 10:46 ` jakub at gcc dot gnu.org
  2023-07-07 10:41 ` [Bug c++/102804] [11 " rguenth at gcc dot gnu.org
  12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-06-28 10:46 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|10.4                        |10.5

--- Comment #10 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 10.4 is being released, retargeting bugs to GCC 10.5.

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

* [Bug c++/102804] [11 Regression] template matching fails w/ false ambiguity on ternary expressions with enums class defined with unsigned typedef
  2021-10-17 22:09 [Bug c++/102804] New: template matching fails w/ false ambiguity on ternary expressions with enums rudick at gmail dot com
                   ` (11 preceding siblings ...)
  2022-06-28 10:46 ` jakub at gcc dot gnu.org
@ 2023-07-07 10:41 ` rguenth at gcc dot gnu.org
  12 siblings, 0 replies; 14+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-07-07 10:41 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|10.5                        |11.5

--- Comment #11 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 10 branch is being closed.

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

end of thread, other threads:[~2023-07-07 10:41 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-17 22:09 [Bug c++/102804] New: template matching fails w/ false ambiguity on ternary expressions with enums rudick at gmail dot com
2021-10-17 22:18 ` [Bug c++/102804] template matching fails w/ false ambiguity on ternary expressions with enums class defined with unsigned int32_t pinskia at gcc dot gnu.org
2021-10-18  0:04 ` [Bug c++/102804] template matching fails w/ false ambiguity on ternary expressions with enums class defined with unsigned typdef redi at gcc dot gnu.org
2021-10-18  0:16 ` redi at gcc dot gnu.org
2021-10-18  6:51 ` rguenth at gcc dot gnu.org
2021-10-18 16:23 ` rudick at gmail dot com
2021-10-18 16:37 ` [Bug c++/102804] [9/10/11/12 Regression] template matching fails w/ false ambiguity on ternary expressions with enums class defined with unsigned typedef redi at gcc dot gnu.org
2021-10-18 16:43 ` redi at gcc dot gnu.org
2021-10-18 21:08 ` pinskia at gcc dot gnu.org
2021-11-05 13:56 ` rguenth at gcc dot gnu.org
2022-04-15  1:55 ` cvs-commit at gcc dot gnu.org
2022-05-27  9:46 ` [Bug c++/102804] [10/11 " rguenth at gcc dot gnu.org
2022-06-28 10:46 ` jakub at gcc dot gnu.org
2023-07-07 10:41 ` [Bug c++/102804] [11 " rguenth 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).