public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/111132] New: Function redeclaration in local scope breaks constant expression evaluation
@ 2023-08-24 12:54 fchelnokov at gmail dot com
  2023-08-24 18:29 ` [Bug c++/111132] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: fchelnokov at gmail dot com @ 2023-08-24 12:54 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111132
           Summary: Function redeclaration in local scope breaks constant
                    expression evaluation
           Product: gcc
           Version: 13.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This program

constexpr bool bar(void) {
    return true;
}

constexpr bool foo() {
    constexpr bool bar(void);
    return bar();
}

static_assert( foo() );


is accepted in Clang, but not in GCC, which prints


error: non-constant condition for static assertion
   10 | static_assert( foo() );
      |                ~~~^~
<source>:10:19:   in 'constexpr' expansion of 'foo()'
<source>:7:15: error: 'constexpr bool bar()' used before its definition
    7 |     return bar();
      |            ~~~^~

Online demo: https://godbolt.org/z/3PvoEx61x

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

* [Bug c++/111132] [11/12/13/14 Regression] Function redeclaration in local scope breaks constant expression evaluation
  2023-08-24 12:54 [Bug c++/111132] New: Function redeclaration in local scope breaks constant expression evaluation fchelnokov at gmail dot com
@ 2023-08-24 18:29 ` pinskia at gcc dot gnu.org
  2023-08-24 19:54 ` ppalka at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-24 18:29 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |8.5.0
      Known to fail|                            |9.1.0
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
           Keywords|                            |needs-bisection
            Summary|Function redeclaration in   |[11/12/13/14 Regression]
                   |local scope breaks constant |Function redeclaration in
                   |expression evaluation       |local scope breaks constant
                   |                            |expression evaluation
   Last reconfirmed|                            |2023-08-24

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

This used to mostly worked in GCC 8.5.0 and before.

In GCC 8.5.0 and before GCC would produce a bogus warning but the static_assert
would worked.

<source>:7:20: warning: inline function 'constexpr bool bar()' used but never
defined
     constexpr bool bar(void);
                    ^~~

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

* [Bug c++/111132] [11/12/13/14 Regression] Function redeclaration in local scope breaks constant expression evaluation
  2023-08-24 12:54 [Bug c++/111132] New: Function redeclaration in local scope breaks constant expression evaluation fchelnokov at gmail dot com
  2023-08-24 18:29 ` [Bug c++/111132] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
@ 2023-08-24 19:54 ` ppalka at gcc dot gnu.org
  2023-10-17 10:27 ` rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-08-24 19:54 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org,
                   |                            |ppalka at gcc dot gnu.org
           Keywords|needs-bisection             |

--- Comment #2 from Patrick Palka <ppalka at gcc dot gnu.org> ---
The error started with with r9-6136-g43574e4ff2afd4

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

* [Bug c++/111132] [11/12/13/14 Regression] Function redeclaration in local scope breaks constant expression evaluation
  2023-08-24 12:54 [Bug c++/111132] New: Function redeclaration in local scope breaks constant expression evaluation fchelnokov at gmail dot com
  2023-08-24 18:29 ` [Bug c++/111132] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
  2023-08-24 19:54 ` ppalka at gcc dot gnu.org
@ 2023-10-17 10:27 ` rguenth at gcc dot gnu.org
  2024-03-07 23:23 ` law at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-10-17 10:27 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

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

* [Bug c++/111132] [11/12/13/14 Regression] Function redeclaration in local scope breaks constant expression evaluation
  2023-08-24 12:54 [Bug c++/111132] New: Function redeclaration in local scope breaks constant expression evaluation fchelnokov at gmail dot com
                   ` (2 preceding siblings ...)
  2023-10-17 10:27 ` rguenth at gcc dot gnu.org
@ 2024-03-07 23:23 ` law at gcc dot gnu.org
  2024-04-01 23:18 ` mpolacek at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: law at gcc dot gnu.org @ 2024-03-07 23:23 UTC (permalink / raw)
  To: gcc-bugs

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

Jeffrey A. Law <law at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |law at gcc dot gnu.org
           Priority|P3                          |P2

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

* [Bug c++/111132] [11/12/13/14 Regression] Function redeclaration in local scope breaks constant expression evaluation
  2023-08-24 12:54 [Bug c++/111132] New: Function redeclaration in local scope breaks constant expression evaluation fchelnokov at gmail dot com
                   ` (3 preceding siblings ...)
  2024-03-07 23:23 ` law at gcc dot gnu.org
@ 2024-04-01 23:18 ` mpolacek at gcc dot gnu.org
  2024-04-05 13:11 ` cvs-commit at gcc dot gnu.org
  2024-04-05 13:26 ` [Bug c++/111132] [11/12/13 " mpolacek at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-04-01 23:18 UTC (permalink / raw)
  To: gcc-bugs

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

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
                 CC|                            |mpolacek at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
I think I have a patch.

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

* [Bug c++/111132] [11/12/13/14 Regression] Function redeclaration in local scope breaks constant expression evaluation
  2023-08-24 12:54 [Bug c++/111132] New: Function redeclaration in local scope breaks constant expression evaluation fchelnokov at gmail dot com
                   ` (4 preceding siblings ...)
  2024-04-01 23:18 ` mpolacek at gcc dot gnu.org
@ 2024-04-05 13:11 ` cvs-commit at gcc dot gnu.org
  2024-04-05 13:26 ` [Bug c++/111132] [11/12/13 " mpolacek at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-04-05 13:11 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from GCC 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:8c9063825ce726fcbbc067d8a6d062cc2d4acf5e

commit r14-9809-g8c9063825ce726fcbbc067d8a6d062cc2d4acf5e
Author: Marek Polacek <polacek@redhat.com>
Date:   Tue Apr 2 12:59:38 2024 -0400

    c++: constexpr error with fn redecl in local scope [PR111132]

    We evaluate constexpr functions on the original, pre-genericization bodies.
    That means that the function body we're evaluating will not have gone
    through cp_genericize_r's "Map block scope extern declarations to visible
    declarations with the same name and type in outer scopes if any".  Here:

      constexpr bool bar() { return true; } // #1
      constexpr bool foo() {
        constexpr bool bar(void); // #2
        return bar();
      }

    it means that we:
    1) register_constexpr_fundef (#1)
    2) cp_genericize (#1)
       nothing interesting happens
    3) register_constexpr_fundef (foo)
       does copy_fn, so we have two copies of the BIND_EXPR
    4) cp_genericize (foo)
       this remaps #2 to #1, but only on one copy of the BIND_EXPR
    5) retrieve_constexpr_fundef (foo)
       we find it, no problem
    6) retrieve_constexpr_fundef (#2)
       and here #2 isn't found in constexpr_fundef_table, because
       we're working on the BIND_EXPR copy where #2 wasn't mapped to #1
       so we fail.  We've only registered #1.

    It should work to use DECL_LOCAL_DECL_ALIAS (which used to be
    extern_decl_map).  We evaluate constexpr functions on pre-cp_fold
    bodies to avoid diagnostic problems, but the remapping I'm proposing
    should not interfere with diagnostics.

    This is not a problem for a global scope redeclaration; there we go
    through duplicate_decls which keeps the DECL_UID:
      DECL_UID (olddecl) = olddecl_uid;
    and DECL_UID is what constexpr_fundef_hasher::hash uses.

            PR c++/111132

    gcc/cp/ChangeLog:

            * constexpr.cc (get_function_named_in_call): Use
            cp_get_fndecl_from_callee.
            * cvt.cc (cp_get_fndecl_from_callee): If there's a
            DECL_LOCAL_DECL_ALIAS, use it.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp0x/constexpr-redeclaration3.C: New test.
            * g++.dg/cpp0x/constexpr-redeclaration4.C: New test.

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

* [Bug c++/111132] [11/12/13 Regression] Function redeclaration in local scope breaks constant expression evaluation
  2023-08-24 12:54 [Bug c++/111132] New: Function redeclaration in local scope breaks constant expression evaluation fchelnokov at gmail dot com
                   ` (5 preceding siblings ...)
  2024-04-05 13:11 ` cvs-commit at gcc dot gnu.org
@ 2024-04-05 13:26 ` mpolacek at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-04-05 13:26 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[11/12/13/14 Regression]    |[11/12/13 Regression]
                   |Function redeclaration in   |Function redeclaration in
                   |local scope breaks constant |local scope breaks constant
                   |expression evaluation       |expression evaluation

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

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

end of thread, other threads:[~2024-04-05 13:26 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-24 12:54 [Bug c++/111132] New: Function redeclaration in local scope breaks constant expression evaluation fchelnokov at gmail dot com
2023-08-24 18:29 ` [Bug c++/111132] [11/12/13/14 Regression] " pinskia at gcc dot gnu.org
2023-08-24 19:54 ` ppalka at gcc dot gnu.org
2023-10-17 10:27 ` rguenth at gcc dot gnu.org
2024-03-07 23:23 ` law at gcc dot gnu.org
2024-04-01 23:18 ` mpolacek at gcc dot gnu.org
2024-04-05 13:11 ` cvs-commit at gcc dot gnu.org
2024-04-05 13:26 ` [Bug c++/111132] [11/12/13 " 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).