public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/100161] New: Impossible to suppress Wtype-limits warning involving template parameter.
@ 2021-04-20 18:50 yyc1992 at gmail dot com
  2021-04-20 19:06 ` [Bug c++/100161] [10/11/12 Regression] " mpolacek at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: yyc1992 at gmail dot com @ 2021-04-20 18:50 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 100161
           Summary: Impossible to suppress Wtype-limits warning involving
                    template parameter.
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: yyc1992 at gmail dot com
  Target Milestone: ---

If a comparison involving a template parameter is always true or false, it
should not raise a warning if it could take other values for other template
parameters.

In particular, the type-limits warning from the code below,

```
void f(unsigned);

template<unsigned n>
void g()
{
    for (unsigned i = 0; i < n; i++) {
        f(i);
    }
}

void h()
{
    g<0>();
}
```

seems to be impossible to suppress. I think this is a regression around GCC 9
time. (I remember seeing it roughly around the same time/slightly after
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90728)

This is partially related to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95148
(which would at least provide a way to suppress the warning).
Also somewhat related to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81642
though supposedly the C++ template example given there is fixed.

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

* [Bug c++/100161] [10/11/12 Regression] Impossible to suppress Wtype-limits warning involving template parameter.
  2021-04-20 18:50 [Bug c++/100161] New: Impossible to suppress Wtype-limits warning involving template parameter yyc1992 at gmail dot com
@ 2021-04-20 19:06 ` mpolacek at gcc dot gnu.org
  2021-04-20 19:10 ` jakub at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-04-20 19:06 UTC (permalink / raw)
  To: gcc-bugs

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

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
   Last reconfirmed|                            |2021-04-20
           Priority|P3                          |P2
            Summary|Impossible to suppress      |[10/11/12 Regression]
                   |Wtype-limits warning        |Impossible to suppress
                   |involving template          |Wtype-limits warning
                   |parameter.                  |involving template
                   |                            |parameter.
                 CC|                            |mpolacek at gcc dot gnu.org
   Target Milestone|---                         |10.4
             Status|UNCONFIRMED                 |ASSIGNED
     Ever confirmed|0                           |1
           Keywords|                            |diagnostic

--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Started with my r11-155.

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

* [Bug c++/100161] [10/11/12 Regression] Impossible to suppress Wtype-limits warning involving template parameter.
  2021-04-20 18:50 [Bug c++/100161] New: Impossible to suppress Wtype-limits warning involving template parameter yyc1992 at gmail dot com
  2021-04-20 19:06 ` [Bug c++/100161] [10/11/12 Regression] " mpolacek at gcc dot gnu.org
@ 2021-04-20 19:10 ` jakub at gcc dot gnu.org
  2021-04-22 21:37 ` cvs-commit at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-04-20 19:10 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Which has been backported to 10 branch in 
r10-8120-ge5613c55c2900cd23c9e78592f10258e19c74ab3

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

* [Bug c++/100161] [10/11/12 Regression] Impossible to suppress Wtype-limits warning involving template parameter.
  2021-04-20 18:50 [Bug c++/100161] New: Impossible to suppress Wtype-limits warning involving template parameter yyc1992 at gmail dot com
  2021-04-20 19:06 ` [Bug c++/100161] [10/11/12 Regression] " mpolacek at gcc dot gnu.org
  2021-04-20 19:10 ` jakub at gcc dot gnu.org
@ 2021-04-22 21:37 ` cvs-commit at gcc dot gnu.org
  2021-04-22 21:38 ` [Bug c++/100161] [10/11 " mpolacek at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-04-22 21:37 UTC (permalink / raw)
  To: gcc-bugs

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

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

https://gcc.gnu.org/g:244dfb95119106e9267f37583caac565c39eb0ec

commit r12-71-g244dfb95119106e9267f37583caac565c39eb0ec
Author: Marek Polacek <polacek@redhat.com>
Date:   Tue Apr 20 20:24:09 2021 -0400

    c++: Prevent bogus -Wtype-limits warning with NTTP [PR100161]

    Recently, we made sure that we never call value_dependent_expression_p
    on an expression that isn't potential_constant_expression.  That caused
    this bogus warning with a non-type template parameter, something that
    users don't want to see.

    The problem is that in tsubst_copy_and_build/LE_EXPR 't' is "i < n",
    which, due to 'i', is not p_c_e, therefore we call t_d_e_p.  But the
    type of 'n' isn't dependent, so we think the whole 't' expression is
    not dependent.  It seems we need to test both op0 and op1 separately
    to suppress this warning.

    gcc/cp/ChangeLog:

            PR c++/100161
            * pt.c (tsubst_copy_and_build) <case PLUS_EXPR>: Test op0 and
            op1 separately for value- or type-dependence.

    gcc/testsuite/ChangeLog:

            PR c++/100161
            * g++.dg/warn/Wtype-limits6.C: New test.

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

* [Bug c++/100161] [10/11 Regression] Impossible to suppress Wtype-limits warning involving template parameter.
  2021-04-20 18:50 [Bug c++/100161] New: Impossible to suppress Wtype-limits warning involving template parameter yyc1992 at gmail dot com
                   ` (2 preceding siblings ...)
  2021-04-22 21:37 ` cvs-commit at gcc dot gnu.org
@ 2021-04-22 21:38 ` mpolacek at gcc dot gnu.org
  2021-04-27 16:41 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-04-22 21:38 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[10/11/12 Regression]       |[10/11 Regression]
                   |Impossible to suppress      |Impossible to suppress
                   |Wtype-limits warning        |Wtype-limits warning
                   |involving template          |involving template
                   |parameter.                  |parameter.

--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed on trunk so far.

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

* [Bug c++/100161] [10/11 Regression] Impossible to suppress Wtype-limits warning involving template parameter.
  2021-04-20 18:50 [Bug c++/100161] New: Impossible to suppress Wtype-limits warning involving template parameter yyc1992 at gmail dot com
                   ` (3 preceding siblings ...)
  2021-04-22 21:38 ` [Bug c++/100161] [10/11 " mpolacek at gcc dot gnu.org
@ 2021-04-27 16:41 ` cvs-commit at gcc dot gnu.org
  2021-05-31 10:40 ` [Bug c++/100161] [10 " marxin at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-04-27 16:41 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

commit r11-8306-gfb7c736c2f17ad054ee7815b688fa91135690f6d
Author: Marek Polacek <polacek@redhat.com>
Date:   Tue Apr 20 20:24:09 2021 -0400

    c++: Prevent bogus -Wtype-limits warning with NTTP [PR100161]

    Recently, we made sure that we never call value_dependent_expression_p
    on an expression that isn't potential_constant_expression.  That caused
    this bogus warning with a non-type template parameter, something that
    users don't want to see.

    The problem is that in tsubst_copy_and_build/LE_EXPR 't' is "i < n",
    which, due to 'i', is not p_c_e, therefore we call t_d_e_p.  But the
    type of 'n' isn't dependent, so we think the whole 't' expression is
    not dependent.  It seems we need to test both op0 and op1 separately
    to suppress this warning.

    gcc/cp/ChangeLog:

            PR c++/100161
            * pt.c (tsubst_copy_and_build) <case PLUS_EXPR>: Test op0 and
            op1 separately for value- or type-dependence.

    gcc/testsuite/ChangeLog:

            PR c++/100161
            * g++.dg/warn/Wtype-limits6.C: New test.

    (cherry picked from commit 244dfb95119106e9267f37583caac565c39eb0ec)

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

* [Bug c++/100161] [10 Regression] Impossible to suppress Wtype-limits warning involving template parameter
  2021-04-20 18:50 [Bug c++/100161] New: Impossible to suppress Wtype-limits warning involving template parameter yyc1992 at gmail dot com
                   ` (4 preceding siblings ...)
  2021-04-27 16:41 ` cvs-commit at gcc dot gnu.org
@ 2021-05-31 10:40 ` marxin at gcc dot gnu.org
  2021-09-13 11:09 ` marxin at gcc dot gnu.org
  2021-12-02 13:29 ` mpolacek at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-05-31 10:40 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

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

--- Comment #6 from Martin Liška <marxin at gcc dot gnu.org> ---
*** Bug 100827 has been marked as a duplicate of this bug. ***

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

* [Bug c++/100161] [10 Regression] Impossible to suppress Wtype-limits warning involving template parameter
  2021-04-20 18:50 [Bug c++/100161] New: Impossible to suppress Wtype-limits warning involving template parameter yyc1992 at gmail dot com
                   ` (5 preceding siblings ...)
  2021-05-31 10:40 ` [Bug c++/100161] [10 " marxin at gcc dot gnu.org
@ 2021-09-13 11:09 ` marxin at gcc dot gnu.org
  2021-12-02 13:29 ` mpolacek at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-09-13 11:09 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andysem at mail dot ru

--- Comment #7 from Martin Liška <marxin at gcc dot gnu.org> ---
*** Bug 102293 has been marked as a duplicate of this bug. ***

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

* [Bug c++/100161] [10 Regression] Impossible to suppress Wtype-limits warning involving template parameter
  2021-04-20 18:50 [Bug c++/100161] New: Impossible to suppress Wtype-limits warning involving template parameter yyc1992 at gmail dot com
                   ` (6 preceding siblings ...)
  2021-09-13 11:09 ` marxin at gcc dot gnu.org
@ 2021-12-02 13:29 ` mpolacek at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2021-12-02 13:29 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #8 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Fixed in 11+.

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

end of thread, other threads:[~2021-12-02 13:29 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-20 18:50 [Bug c++/100161] New: Impossible to suppress Wtype-limits warning involving template parameter yyc1992 at gmail dot com
2021-04-20 19:06 ` [Bug c++/100161] [10/11/12 Regression] " mpolacek at gcc dot gnu.org
2021-04-20 19:10 ` jakub at gcc dot gnu.org
2021-04-22 21:37 ` cvs-commit at gcc dot gnu.org
2021-04-22 21:38 ` [Bug c++/100161] [10/11 " mpolacek at gcc dot gnu.org
2021-04-27 16:41 ` cvs-commit at gcc dot gnu.org
2021-05-31 10:40 ` [Bug c++/100161] [10 " marxin at gcc dot gnu.org
2021-09-13 11:09 ` marxin at gcc dot gnu.org
2021-12-02 13:29 ` mpolacek 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).