public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/109083] New: Incorrect static_assert shown in diagnostics
@ 2023-03-09 19:23 markus-t314 at gmx dot de
  2023-03-09 19:37 ` [Bug c++/109083] [10/11/12/13 Regression] " pinskia at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: markus-t314 at gmx dot de @ 2023-03-09 19:23 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 109083
           Summary: Incorrect static_assert shown in diagnostics
           Product: gcc
           Version: 12.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: markus-t314 at gmx dot de
  Target Milestone: ---

Code:

#include <type_traits>

template<typename T>
void unused_function()
{
    static_assert(std::is_member_function_pointer<decltype(&T::foo)>::value,
"Line 6");
}

template<typename T>
void fail_here()
{
    static_assert(std::is_member_function_pointer<decltype(&T::foo)>::value,
"Line 12");
}

int main()
{
    fail_here<int>();
}



This fails correctly, but the wrong static assertion is given in diagnostics:

main.cpp: In instantiation of ‘void fail_here() [with T = int]’:
main.cpp:17:19:   required from here
main.cpp:6:60: error: ‘foo’ is not a member of ‘int’
    6 |    
static_assert(std::is_member_function_pointer<decltype(&T::foo)>::value, "Line
6");
      |


https://godbolt.org/z/6Yrc9x6Ws


Might be related to bug 66968

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

* [Bug c++/109083] [10/11/12/13 Regression] Incorrect static_assert shown in diagnostics
  2023-03-09 19:23 [Bug c++/109083] New: Incorrect static_assert shown in diagnostics markus-t314 at gmx dot de
@ 2023-03-09 19:37 ` pinskia at gcc dot gnu.org
  2023-03-15 10:49 ` jakub at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-03-09 19:37 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |13.0
            Summary|Incorrect static_assert     |[10/11/12/13 Regression]
                   |shown in diagnostics        |Incorrect static_assert
                   |                            |shown in diagnostics
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
           Keywords|                            |needs-bisection
      Known to work|                            |4.5.3, 4.6.4, 4.7.1, 4.7.4
   Last reconfirmed|                            |2023-03-09

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.

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

* [Bug c++/109083] [10/11/12/13 Regression] Incorrect static_assert shown in diagnostics
  2023-03-09 19:23 [Bug c++/109083] New: Incorrect static_assert shown in diagnostics markus-t314 at gmx dot de
  2023-03-09 19:37 ` [Bug c++/109083] [10/11/12/13 Regression] " pinskia at gcc dot gnu.org
@ 2023-03-15 10:49 ` jakub at gcc dot gnu.org
  2023-03-15 11:40 ` jakub at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-03-15 10:49 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
What happens is that finish_template_type is called once from unused_function
with
is_member_function_pointer TEMPLATE_DECL as name and args
 <tree_vec 0x7fffea2fd2e0 length:1
    elt:0 <decltype_type 0x7fffea2fc930 VOID
        align:8 warn_if_not_align:0 symtab:0 alias-set -1 structural-equality
        expr <addr_expr 0x7fffea2fd2c0 type <dependent_operator_type
0x7fffea2fc888>

            arg:0 <scope_ref 0x7fffea2fbd20 tree_0 arg:0 <template_type_parm
0x7fffea2fc738 T>
                arg:1 <identifier_node 0x7fffea2e9cc0 foo
                    normal local bindings <(nil)>>
                pr109083.ii:86:64 start: pr109083.ii:86:64 finish:
pr109083.ii:86:66>
            pr109083.ii:86:60 start: pr109083.ii:86:60 finish:
pr109083.ii:86:66>>>
(in my case of reduced preprocessed source), calls lookup_template_class, finds
nothing in
9943          entry = type_specializations->find_with_hash (&elt, hash);
and so creates
10082             t = make_class_type (TREE_CODE (template_type));
etc.
Next time finish_template_type is called from fail_here with the same
TEMPLATE_DECL as name and args
 <tree_vec 0x7fffea2fd400 length:1
    elt:0 <decltype_type 0x7fffea2fcf18 VOID
        align:8 warn_if_not_align:0 symtab:0 alias-set -1 structural-equality
        expr <addr_expr 0x7fffea2fd3e0 type <dependent_operator_type
0x7fffea2fce70>

            arg:0 <scope_ref 0x7fffea302000 tree_0 arg:0 <template_type_parm
0x7fffea2fcd20 T>
                arg:1 <identifier_node 0x7fffea2e9cc0 foo
                    normal local bindings <(nil)>>
                pr109083.ii:92:64 start: pr109083.ii:92:64 finish:
pr109083.ii:92:66>
            pr109083.ii:92:60 start: pr109083.ii:92:60 finish:
pr109083.ii:92:66>>>
but this type the previously created specialization from unused_function is
returned.

So, shall template_args_equal or whatever it calls be changed so that it
doesn't consider these to be equal?  If so, what compilation memory effects
will it have?

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

* [Bug c++/109083] [10/11/12/13 Regression] Incorrect static_assert shown in diagnostics
  2023-03-09 19:23 [Bug c++/109083] New: Incorrect static_assert shown in diagnostics markus-t314 at gmx dot de
  2023-03-09 19:37 ` [Bug c++/109083] [10/11/12/13 Regression] " pinskia at gcc dot gnu.org
  2023-03-15 10:49 ` jakub at gcc dot gnu.org
@ 2023-03-15 11:40 ` jakub at gcc dot gnu.org
  2023-03-15 14:29 ` rguenth at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-03-15 11:40 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|needs-bisection             |

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
I think this started with r0-116872-gf330f5991ef0182d59ab.

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

* [Bug c++/109083] [10/11/12/13 Regression] Incorrect static_assert shown in diagnostics
  2023-03-09 19:23 [Bug c++/109083] New: Incorrect static_assert shown in diagnostics markus-t314 at gmx dot de
                   ` (2 preceding siblings ...)
  2023-03-15 11:40 ` jakub at gcc dot gnu.org
@ 2023-03-15 14:29 ` rguenth at gcc dot gnu.org
  2023-03-15 14:33 ` jakub at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-03-15 14:29 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
I wonder why we instantiate from unused_function (but don't diagnose) at all?

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

* [Bug c++/109083] [10/11/12/13 Regression] Incorrect static_assert shown in diagnostics
  2023-03-09 19:23 [Bug c++/109083] New: Incorrect static_assert shown in diagnostics markus-t314 at gmx dot de
                   ` (3 preceding siblings ...)
  2023-03-15 14:29 ` rguenth at gcc dot gnu.org
@ 2023-03-15 14:33 ` jakub at gcc dot gnu.org
  2023-03-15 17:42 ` jason at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-03-15 14:33 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
We don't instantiate in that case, just look up a specialization which might be
or might not be later instantiated (which is when it is diagnosed).
One way to fix this would be to drop locations from the expressions in the
template arguments if we use them from multiple spots.  But that could result
in less accurate diagnostics.

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

* [Bug c++/109083] [10/11/12/13 Regression] Incorrect static_assert shown in diagnostics
  2023-03-09 19:23 [Bug c++/109083] New: Incorrect static_assert shown in diagnostics markus-t314 at gmx dot de
                   ` (4 preceding siblings ...)
  2023-03-15 14:33 ` jakub at gcc dot gnu.org
@ 2023-03-15 17:42 ` jason at gcc dot gnu.org
  2023-03-27  8:11 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jason at gcc dot gnu.org @ 2023-03-15 17:42 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Jason Merrill <jason at gcc dot gnu.org> ---
Created attachment 54673
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54673&action=edit
first try

Another approach would be to treat the expressions as different for the
*_specializations hash tables, as per this patch, which fixes the testcase. 
But as is this patch breaks the standard library, so more work would need to be
done to make type canonicalization continue to work.

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

* [Bug c++/109083] [10/11/12/13 Regression] Incorrect static_assert shown in diagnostics
  2023-03-09 19:23 [Bug c++/109083] New: Incorrect static_assert shown in diagnostics markus-t314 at gmx dot de
                   ` (5 preceding siblings ...)
  2023-03-15 17:42 ` jason at gcc dot gnu.org
@ 2023-03-27  8:11 ` rguenth at gcc dot gnu.org
  2023-04-26  6:58 ` [Bug c++/109083] [10/11/12/13/14 " rguenth at gcc dot gnu.org
  2023-07-27  9:25 ` [Bug c++/109083] [11/12/13/14 " rguenth at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-03-27  8:11 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

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

* [Bug c++/109083] [10/11/12/13/14 Regression] Incorrect static_assert shown in diagnostics
  2023-03-09 19:23 [Bug c++/109083] New: Incorrect static_assert shown in diagnostics markus-t314 at gmx dot de
                   ` (6 preceding siblings ...)
  2023-03-27  8:11 ` rguenth at gcc dot gnu.org
@ 2023-04-26  6:58 ` rguenth at gcc dot gnu.org
  2023-07-27  9:25 ` [Bug c++/109083] [11/12/13/14 " rguenth at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-04-26  6:58 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 13.1 is being released, retargeting bugs to GCC 13.2.

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

* [Bug c++/109083] [11/12/13/14 Regression] Incorrect static_assert shown in diagnostics
  2023-03-09 19:23 [Bug c++/109083] New: Incorrect static_assert shown in diagnostics markus-t314 at gmx dot de
                   ` (7 preceding siblings ...)
  2023-04-26  6:58 ` [Bug c++/109083] [10/11/12/13/14 " rguenth at gcc dot gnu.org
@ 2023-07-27  9:25 ` rguenth at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-07-27  9:25 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|13.2                        |13.3

--- Comment #8 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 13.2 is being released, retargeting bugs to GCC 13.3.

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

end of thread, other threads:[~2023-07-27  9:25 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-09 19:23 [Bug c++/109083] New: Incorrect static_assert shown in diagnostics markus-t314 at gmx dot de
2023-03-09 19:37 ` [Bug c++/109083] [10/11/12/13 Regression] " pinskia at gcc dot gnu.org
2023-03-15 10:49 ` jakub at gcc dot gnu.org
2023-03-15 11:40 ` jakub at gcc dot gnu.org
2023-03-15 14:29 ` rguenth at gcc dot gnu.org
2023-03-15 14:33 ` jakub at gcc dot gnu.org
2023-03-15 17:42 ` jason at gcc dot gnu.org
2023-03-27  8:11 ` rguenth at gcc dot gnu.org
2023-04-26  6:58 ` [Bug c++/109083] [10/11/12/13/14 " rguenth at gcc dot gnu.org
2023-07-27  9:25 ` [Bug c++/109083] [11/12/13/14 " 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).