public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/105436] New: parse error with >= operator expression in template argument list in C++14 mode since r13-40
@ 2022-04-29 19:31 ppalka at gcc dot gnu.org
  2022-04-29 19:36 ` [Bug c++/105436] [13 Regression] " mpolacek at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-04-29 19:31 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 105436
           Summary: parse error with >= operator expression in template
                    argument list in C++14 mode since r13-40
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ppalka at gcc dot gnu.org
  Target Milestone: ---

After r13-40-ga282da2243103d we reject the following presumably valid snippet
in C++14 mode (and earlier):

template<bool> struct A;
template<int N> A<N >= 5> f();

with the parse error:

testcase.C:2:21: error: ‘>=’ should be ‘> =’ to terminate a template argument
list
    2 | template<int N> A<N >= 5> f();
      |                     ^~
      |                     > =
testcase.C:2:24: error: expected unqualified-id before numeric constant
    2 | template<int N> A<N >= 5> f();

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

* [Bug c++/105436] [13 Regression] parse error with >= operator expression in template argument list in C++14 mode since r13-40
  2022-04-29 19:31 [Bug c++/105436] New: parse error with >= operator expression in template argument list in C++14 mode since r13-40 ppalka at gcc dot gnu.org
@ 2022-04-29 19:36 ` mpolacek at gcc dot gnu.org
  2022-04-29 19:57 ` mpolacek at gcc dot gnu.org
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-04-29 19:36 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2022-04-29
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
                 CC|                            |mpolacek at gcc dot gnu.org
           Keywords|                            |rejects-valid

--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Confirmed.

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

* [Bug c++/105436] [13 Regression] parse error with >= operator expression in template argument list in C++14 mode since r13-40
  2022-04-29 19:31 [Bug c++/105436] New: parse error with >= operator expression in template argument list in C++14 mode since r13-40 ppalka at gcc dot gnu.org
  2022-04-29 19:36 ` [Bug c++/105436] [13 Regression] " mpolacek at gcc dot gnu.org
@ 2022-04-29 19:57 ` mpolacek at gcc dot gnu.org
  2022-04-29 20:20 ` mpolacek at gcc dot gnu.org
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-04-29 19:57 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
The C++14 vs C++17 difference is due to:

  /* It must be a non-type argument.  In C++17 any constant-expression is
     allowed.  */
  if (cxx_dialect > cxx14)
    goto general_expr;

in cp_parser_template_argument.  So in C++14 we get "N" as the targ but in
C++17 it is the whole "N >= 5" expression.

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

* [Bug c++/105436] [13 Regression] parse error with >= operator expression in template argument list in C++14 mode since r13-40
  2022-04-29 19:31 [Bug c++/105436] New: parse error with >= operator expression in template argument list in C++14 mode since r13-40 ppalka at gcc dot gnu.org
  2022-04-29 19:36 ` [Bug c++/105436] [13 Regression] " mpolacek at gcc dot gnu.org
  2022-04-29 19:57 ` mpolacek at gcc dot gnu.org
@ 2022-04-29 20:20 ` mpolacek at gcc dot gnu.org
  2022-04-29 20:41 ` pinskia at gcc dot gnu.org
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-04-29 20:20 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
I think the fix is just

--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -33224,7 +33224,6 @@ cp_parser_next_token_ends_template_argument_p
(cp_parser *parser)
      || ((cxx_dialect != cxx98) && token->type == CPP_RSHIFT)
      /* For better diagnostics, treat >>= like that too, that
         shouldn't appear non-nested in template arguments.  */
-     || token->type == CPP_GREATER_EQ
      || token->type == CPP_RSHIFT_EQ);
 }


it doesn't regress anything and fixes this test.  Probably just an oversight,
the code doesn't match the comment.

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

* [Bug c++/105436] [13 Regression] parse error with >= operator expression in template argument list in C++14 mode since r13-40
  2022-04-29 19:31 [Bug c++/105436] New: parse error with >= operator expression in template argument list in C++14 mode since r13-40 ppalka at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2022-04-29 20:20 ` mpolacek at gcc dot gnu.org
@ 2022-04-29 20:41 ` pinskia at gcc dot gnu.org
  2022-04-30  7:11 ` jakub at gcc dot gnu.org
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-04-29 20:41 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |13.0

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

* [Bug c++/105436] [13 Regression] parse error with >= operator expression in template argument list in C++14 mode since r13-40
  2022-04-29 19:31 [Bug c++/105436] New: parse error with >= operator expression in template argument list in C++14 mode since r13-40 ppalka at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2022-04-29 20:41 ` pinskia at gcc dot gnu.org
@ 2022-04-30  7:11 ` jakub at gcc dot gnu.org
  2022-04-30 14:38 ` mpolacek at gcc dot gnu.org
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-04-30  7:11 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Marek, I think you're right.  I meant to follow what is done for C++98
CPP_RSHIFT with CPP_GREATER_EQ, but here actually CPP_RSHIFT isn't special in
C++98.

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

* [Bug c++/105436] [13 Regression] parse error with >= operator expression in template argument list in C++14 mode since r13-40
  2022-04-29 19:31 [Bug c++/105436] New: parse error with >= operator expression in template argument list in C++14 mode since r13-40 ppalka at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2022-04-30  7:11 ` jakub at gcc dot gnu.org
@ 2022-04-30 14:38 ` mpolacek at gcc dot gnu.org
  2022-05-02  6:45 ` rguenth at gcc dot gnu.org
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-04-30 14:38 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |mpolacek at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

--- Comment #5 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Thanks.  I'll take care of it.

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

* [Bug c++/105436] [13 Regression] parse error with >= operator expression in template argument list in C++14 mode since r13-40
  2022-04-29 19:31 [Bug c++/105436] New: parse error with >= operator expression in template argument list in C++14 mode since r13-40 ppalka at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2022-04-30 14:38 ` mpolacek at gcc dot gnu.org
@ 2022-05-02  6:45 ` rguenth at gcc dot gnu.org
  2022-05-02 11:28 ` slyfox at gcc dot gnu.org
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-05-02  6:45 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P1

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

* [Bug c++/105436] [13 Regression] parse error with >= operator expression in template argument list in C++14 mode since r13-40
  2022-04-29 19:31 [Bug c++/105436] New: parse error with >= operator expression in template argument list in C++14 mode since r13-40 ppalka at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2022-05-02  6:45 ` rguenth at gcc dot gnu.org
@ 2022-05-02 11:28 ` slyfox at gcc dot gnu.org
  2022-05-04 15:13 ` mpolacek at gcc dot gnu.org
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: slyfox at gcc dot gnu.org @ 2022-05-02 11:28 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Sergei Trofimovich <slyfox at gcc dot gnu.org> ---
Noticed similar build failure on llvm-13:

[  1%] Building CXX object
utils/TableGen/CMakeFiles/obj.llvm-tblgen.dir/AsmMatcherEmitter.cpp.o
In file included from /build/source/llvm/include/llvm/ADT/Sequence.h:23,
                 from
/build/source/llvm/include/llvm/Support/MachineValueType.h:17,
                 from
/build/source/llvm/utils/TableGen/CodeGenInstruction.h:17,
                 from /build/source/llvm/utils/TableGen/CodeGenTarget.h:20,
                 from
/build/source/llvm/utils/TableGen/AsmMatcherEmitter.cpp:98:
/build/source/llvm/include/llvm/Support/MathExtras.h:400:37: error: '>=' should
be '> =' to terminate a template argument list
  400 | constexpr inline std::enable_if_t<N >= 64, bool> isUInt(uint64_t) {
      |                                     ^~
      |                                     > =
/build/source/llvm/include/llvm/Support/MathExtras.h:400:40: error: expected
unqualified-id before numeric constant
  400 | constexpr inline std::enable_if_t<N >= 64, bool> isUInt(uint64_t) {
      |                                        ^~

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

* [Bug c++/105436] [13 Regression] parse error with >= operator expression in template argument list in C++14 mode since r13-40
  2022-04-29 19:31 [Bug c++/105436] New: parse error with >= operator expression in template argument list in C++14 mode since r13-40 ppalka at gcc dot gnu.org
                   ` (7 preceding siblings ...)
  2022-05-02 11:28 ` slyfox at gcc dot gnu.org
@ 2022-05-04 15:13 ` mpolacek at gcc dot gnu.org
  2022-05-04 16:02 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-05-04 15:13 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pdimov at gmail dot com

--- Comment #7 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
*** Bug 105482 has been marked as a duplicate of this bug. ***

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

* [Bug c++/105436] [13 Regression] parse error with >= operator expression in template argument list in C++14 mode since r13-40
  2022-04-29 19:31 [Bug c++/105436] New: parse error with >= operator expression in template argument list in C++14 mode since r13-40 ppalka at gcc dot gnu.org
                   ` (8 preceding siblings ...)
  2022-05-04 15:13 ` mpolacek at gcc dot gnu.org
@ 2022-05-04 16:02 ` cvs-commit at gcc dot gnu.org
  2022-05-04 16:03 ` mpolacek at gcc dot gnu.org
  2022-05-04 16:32 ` jakub at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-05-04 16:02 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:79a1a01cbd0e4a491d7078783131e3f88ca7158d

commit r13-115-g79a1a01cbd0e4a491d7078783131e3f88ca7158d
Author: Marek Polacek <polacek@redhat.com>
Date:   Fri Apr 29 17:03:41 2022 -0400

    c++: parse error with >= in template argument list [PR105436]

    This patch fixes an oversight whereby we treated >= as the end of
    a template argument.  This causes problems in C++14, because in
    cp_parser_template_argument we go different ways for C++14 and C++17:

      /* It must be a non-type argument.  In C++17 any constant-expression is
         allowed.  */
      if (cxx_dialect > cxx14)
        goto general_expr;

    so in this testcase in C++14 we get "N" as the template argument but in
    C++17 it is the whole "N >= 5" expression.  So in C++14 the remaining
    ">= 5" triggered the newly-added diagnostic.

            PR c++/105436

    gcc/cp/ChangeLog:

            * parser.cc (cp_parser_next_token_ends_template_argument_p): Don't
            return true for CPP_GREATER_EQ.

    gcc/testsuite/ChangeLog:

            * g++.dg/parse/template31.C: New test.

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

* [Bug c++/105436] [13 Regression] parse error with >= operator expression in template argument list in C++14 mode since r13-40
  2022-04-29 19:31 [Bug c++/105436] New: parse error with >= operator expression in template argument list in C++14 mode since r13-40 ppalka at gcc dot gnu.org
                   ` (9 preceding siblings ...)
  2022-05-04 16:02 ` cvs-commit at gcc dot gnu.org
@ 2022-05-04 16:03 ` mpolacek at gcc dot gnu.org
  2022-05-04 16:32 ` jakub at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-05-04 16:03 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #9 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed.

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

* [Bug c++/105436] [13 Regression] parse error with >= operator expression in template argument list in C++14 mode since r13-40
  2022-04-29 19:31 [Bug c++/105436] New: parse error with >= operator expression in template argument list in C++14 mode since r13-40 ppalka at gcc dot gnu.org
                   ` (10 preceding siblings ...)
  2022-05-04 16:03 ` mpolacek at gcc dot gnu.org
@ 2022-05-04 16:32 ` jakub at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-05-04 16:32 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Thanks and sorry.

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

end of thread, other threads:[~2022-05-04 16:32 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-29 19:31 [Bug c++/105436] New: parse error with >= operator expression in template argument list in C++14 mode since r13-40 ppalka at gcc dot gnu.org
2022-04-29 19:36 ` [Bug c++/105436] [13 Regression] " mpolacek at gcc dot gnu.org
2022-04-29 19:57 ` mpolacek at gcc dot gnu.org
2022-04-29 20:20 ` mpolacek at gcc dot gnu.org
2022-04-29 20:41 ` pinskia at gcc dot gnu.org
2022-04-30  7:11 ` jakub at gcc dot gnu.org
2022-04-30 14:38 ` mpolacek at gcc dot gnu.org
2022-05-02  6:45 ` rguenth at gcc dot gnu.org
2022-05-02 11:28 ` slyfox at gcc dot gnu.org
2022-05-04 15:13 ` mpolacek at gcc dot gnu.org
2022-05-04 16:02 ` cvs-commit at gcc dot gnu.org
2022-05-04 16:03 ` mpolacek at gcc dot gnu.org
2022-05-04 16:32 ` jakub 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).