public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/95968] New: error: 'args#0' is not a constant expression
@ 2020-06-29 15:39 zakeria433 at gmail dot com
  2020-07-08 22:45 ` [Bug c++/95968] " mpolacek at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: zakeria433 at gmail dot com @ 2020-06-29 15:39 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 95968
           Summary: error: 'args#0' is not a constant expression
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zakeria433 at gmail dot com
  Target Milestone: ---

Hi,

command: g++ test_class.cpp -Wall -Wextra -std=c++20
System: Debian 10

The following code is rejected by Gcc 10.1. However, if I replace test_class's
constructor with constexpr instead of consteval, it does compile on gcc.

// Example program
#include <tuple>
#include <type_traits>
// #include <concepts>

template<typename T, typename ... Pack>
requires(std::is_floating_point<T>::value)
class test_class
{
public:
    const T first_param;
    const std::tuple <Pack...> pack;

    consteval test_class(T first_param_, Pack... pack_) :
first_param(first_param_), 
    pack(pack_...)
    {
    }

    consteval auto test_func()
    {
        //auto p = first_param;
        auto x = std::apply([/*p*/](const auto ... args) {return
test_class(1.0, args...);}, pack);
        return x;
    }
};

int main()
{
     constexpr auto var1 = test_class(4.0);
     //constexpr auto var2 = test_class(5.0);
     constexpr auto var3 = test_class(12.0, var1).test_func();
     //static_assert(vart3.first_param == 12, "assert fail");
}
error: ‘args#0’ is not a constant expression
   22 |         auto x = std::apply([/*p*/](const auto ... args) {return
test_class(1.0, args...);}, pack);
      |                                                                 
^~~~~~~~~~~~~~~~~~~~~~~~


Live demo:
https://godbolt.org/z/oWWFaP

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

* [Bug c++/95968] error: 'args#0' is not a constant expression
  2020-06-29 15:39 [Bug c++/95968] New: error: 'args#0' is not a constant expression zakeria433 at gmail dot com
@ 2020-07-08 22:45 ` mpolacek at gcc dot gnu.org
  2021-10-02  6:05 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-07-08 22:45 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mpolacek at gcc dot gnu.org
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2020-07-08
     Ever confirmed|0                           |1

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

* [Bug c++/95968] error: 'args#0' is not a constant expression
  2020-06-29 15:39 [Bug c++/95968] New: error: 'args#0' is not a constant expression zakeria433 at gmail dot com
  2020-07-08 22:45 ` [Bug c++/95968] " mpolacek at gcc dot gnu.org
@ 2021-10-02  6:05 ` pinskia at gcc dot gnu.org
  2022-01-17 10:52 ` pinskia at gcc dot gnu.org
  2023-01-19  1:26 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-10-02  6:05 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Hmm, clang also rejects this (even with libc++).

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

* [Bug c++/95968] error: 'args#0' is not a constant expression
  2020-06-29 15:39 [Bug c++/95968] New: error: 'args#0' is not a constant expression zakeria433 at gmail dot com
  2020-07-08 22:45 ` [Bug c++/95968] " mpolacek at gcc dot gnu.org
  2021-10-02  6:05 ` pinskia at gcc dot gnu.org
@ 2022-01-17 10:52 ` pinskia at gcc dot gnu.org
  2023-01-19  1:26 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-17 10:52 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
             Blocks|                            |55004, 54367

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The following is the reduced testcase:
struct test_class
{
    consteval test_class( double pack_) { }
};

void test_func() 
{
    auto t = [](const auto... args) {return test_class(args...);};
    t(1.0);
}

are lambdas consteval by default? I know they are implicit constexpr but I
don't think they are consteval though.
There is still a diagnostic issue where args#0 is used as it should be args...
instead and maybe a little more clear why args... is not a constant value
expression.

Clang gives:
<source>:8:45: error: call to consteval function 'test_class::test_class' is
not a constant expression
    auto t = [](const auto... args) {return test_class(args...);};
                                            ^
<source>:9:6: note: in instantiation of function template specialization
'test_func()::(anonymous class)::operator()<double>' requested here
    t(1.0);
     ^
<source>:8:56: note: function parameter 'args' with unknown value cannot be
used in a constant expression
    auto t = [](const auto... args) {return test_class(args...);};
                                                       ^
<source>:8:31: note: declared here
    auto t = [](const auto... args) {return test_class(args...);};
                              ^


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54367
[Bug 54367] [meta-bug] lambda expressions
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55004
[Bug 55004] [meta-bug] constexpr issues

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

* [Bug c++/95968] error: 'args#0' is not a constant expression
  2020-06-29 15:39 [Bug c++/95968] New: error: 'args#0' is not a constant expression zakeria433 at gmail dot com
                   ` (2 preceding siblings ...)
  2022-01-17 10:52 ` pinskia at gcc dot gnu.org
@ 2023-01-19  1:26 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-01-19  1:26 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|rejects-valid               |

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #2)
> The following is the reduced testcase:
> struct test_class
> {
>     consteval test_class( double pack_) { }
> };
> 
> void test_func() 
> {
>     auto t = [](const auto... args) {return test_class(args...);};
>     t(1.0);
> }
> 
> are lambdas consteval by default? I know they are implicit constexpr but I
> don't think they are consteval though.

They are not until C++23 (See PR 107687 for the status on that).

This is just a diagnostic issue. add constevalue like this to the reduced
testcase allows the testcase to work:
    auto t = [](const auto... args) consteval {return test_class(args...);};

Note the original testcase still has issues even if you add consteval to the
lambda and I suspect because std::apply still has issues ...

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

end of thread, other threads:[~2023-01-19  1:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-29 15:39 [Bug c++/95968] New: error: 'args#0' is not a constant expression zakeria433 at gmail dot com
2020-07-08 22:45 ` [Bug c++/95968] " mpolacek at gcc dot gnu.org
2021-10-02  6:05 ` pinskia at gcc dot gnu.org
2022-01-17 10:52 ` pinskia at gcc dot gnu.org
2023-01-19  1:26 ` pinskia 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).