public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/103443] New: consteval function rejected as constant expression
@ 2021-11-26 14:56 vincent.hamp at higaski dot at
  2021-11-26 16:32 ` [Bug c++/103443] " jakub at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: vincent.hamp at higaski dot at @ 2021-11-26 14:56 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 103443
           Summary: consteval function rejected as constant expression
           Product: gcc
           Version: 11.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vincent.hamp at higaski dot at
  Target Milestone: ---

Not really sure whether that's a frontend or a libstdc++ bug, but GCC 11.1.0
(and according to godbolt trunk as well) does not accept the following snippet.


#include <cstdint>
#include <cstdio>
#include <utility>

// #define QUALIFIER constexpr // compiles
#define QUALIFIER consteval    // does not compile

template <size_t... Is>
QUALIFIER uint32_t index_sequence2mask(std::index_sequence<Is...>) {
    if constexpr (sizeof...(Is) == 0u)
        return 0u;
    else
        return ((1u << Is) | ...);
}

template <uint32_t Mask = index_sequence2mask(std::make_index_sequence<1u>{})>
void use_mask() {
    printf("%s\n", __PRETTY_FUNCTION__);
}

int main() { use_mask(); }


The code is rejected with the following error:
"expression 'std::make_index_sequence<1>{}' is not a constant expression"

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

* [Bug c++/103443] consteval function rejected as constant expression
  2021-11-26 14:56 [Bug c++/103443] New: consteval function rejected as constant expression vincent.hamp at higaski dot at
@ 2021-11-26 16:32 ` jakub at gcc dot gnu.org
  2022-03-04 15:17 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-11-26 16:32 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2021-11-26
                 CC|                            |jakub at gcc dot gnu.org,
                   |                            |jason at gcc dot gnu.org,
                   |                            |ppalka at gcc dot gnu.org

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Seems while parsing the default argument of the template parameter
finish_call_expr notes the argument of the index_sequence2mask call is
non-dependent, so make_args_non_dependent wraps that argument with
NON_DEPENDENT_EXPR.
But later we call build_new_function_call -> build_over_call ->
fold_non_dependent_expr -> fold_non_dependent_expr_template ->
instantiate_non_dependent_expr_internal -> tsubst_copy_and_build
which instantiates it, but the NON_DEPENDENT_EXPR is still among the arguments.
Later build_over_call sees it is a call to an immediate function and so calls
cxx_constant_value on it, but the constant evaluation fails because
NON_DEPENDENT_EXPR isn't handled in constexpr.c at all.
Shall constexpr.c handle NON_DEPENDENT_EXPR, or can that wrap expressions that
really can't be constant expression evaluated?

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

* [Bug c++/103443] consteval function rejected as constant expression
  2021-11-26 14:56 [Bug c++/103443] New: consteval function rejected as constant expression vincent.hamp at higaski dot at
  2021-11-26 16:32 ` [Bug c++/103443] " jakub at gcc dot gnu.org
@ 2022-03-04 15:17 ` cvs-commit at gcc dot gnu.org
  2022-03-04 15:29 ` ppalka at gcc dot gnu.org
  2022-03-04 15:29 ` ppalka at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-03-04 15:17 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:074d283e249c7295d783a08eb6f0219a7f411c50

commit r12-7488-g074d283e249c7295d783a08eb6f0219a7f411c50
Author: Patrick Palka <ppalka@redhat.com>
Date:   Fri Mar 4 10:17:30 2022 -0500

    c++: Add testcase for already fixed PR [PR103443]

    Fixed by r12-7264.

            PR c++/103443

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp2a/consteval29.C: New test.

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

* [Bug c++/103443] consteval function rejected as constant expression
  2021-11-26 14:56 [Bug c++/103443] New: consteval function rejected as constant expression vincent.hamp at higaski dot at
  2021-11-26 16:32 ` [Bug c++/103443] " jakub at gcc dot gnu.org
  2022-03-04 15:17 ` cvs-commit at gcc dot gnu.org
@ 2022-03-04 15:29 ` ppalka at gcc dot gnu.org
  2022-03-04 15:29 ` ppalka at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-03-04 15:29 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Patrick Palka <ppalka at gcc dot gnu.org> ---
(In reply to Jakub Jelinek from comment #1)
> Shall constexpr.c handle NON_DEPENDENT_EXPR, or can that wrap expressions
> that really can't be constant expression evaluated?

r12-7264 made potential_constant_expression return false for NON_DEPENDENT_EXPR
since neither constexpr evaluation nor tsubst currently handle it, so for this
testcase we now avoid the bogus error that would have been emitted during ahead
of time evaluation of the consteval call.

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

* [Bug c++/103443] consteval function rejected as constant expression
  2021-11-26 14:56 [Bug c++/103443] New: consteval function rejected as constant expression vincent.hamp at higaski dot at
                   ` (2 preceding siblings ...)
  2022-03-04 15:29 ` ppalka at gcc dot gnu.org
@ 2022-03-04 15:29 ` ppalka at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-03-04 15:29 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |12.0
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED

--- Comment #4 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for GCC 12, thanks for the bug report.

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

end of thread, other threads:[~2022-03-04 15:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-26 14:56 [Bug c++/103443] New: consteval function rejected as constant expression vincent.hamp at higaski dot at
2021-11-26 16:32 ` [Bug c++/103443] " jakub at gcc dot gnu.org
2022-03-04 15:17 ` cvs-commit at gcc dot gnu.org
2022-03-04 15:29 ` ppalka at gcc dot gnu.org
2022-03-04 15:29 ` ppalka 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).