public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/99895] New: Function parameters generated wrong in call to member of non-type template parameter in lambda
@ 2021-04-03 8:56 bisqwit at iki dot fi
2021-05-27 19:29 ` [Bug c++/99895] " ppalka at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: bisqwit at iki dot fi @ 2021-04-03 8:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99895
Bug ID: 99895
Summary: Function parameters generated wrong in call to member
of non-type template parameter in lambda
Product: gcc
Version: 10.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: bisqwit at iki dot fi
Target Milestone: ---
GCC produces false error message:
bug1.cc: In instantiation of ‘consteval void VerifyHash() [with unsigned int
expected_hash = 5; fixed_string<...auto...> ...s = {fixed_string<6>{"khaki"},
fixed_string<6>{"plums"}}]’:
bug1.cc:24:37: required from here
bug1.cc:19:41: error: no matching function for call to
‘fixed_string<6>::data(const fixed_string<6>*)’
19 | [](auto){static_assert(hash(s.data(), s.size()) ==
expected_hash);}(s)
| ~~~~~~^~
bug1.cc:11:27: note: candidate: ‘consteval const char* fixed_string<N>::data()
const [with long unsigned int N = 6]’
11 | consteval const char* data() const { return str; }
| ^~~~
bug1.cc:11:27: note: candidate expects 0 arguments, 1 provided
On this code:
#include <algorithm> // copy_n and size_t
static constexpr unsigned hash(const char* s, std::size_t length)
{
s=s;
return length;
}
template<std::size_t N>
struct fixed_string
{
constexpr fixed_string(const char (&s)[N]) { std::copy_n(s, N, str); }
consteval const char* data() const { return str; }
consteval std::size_t size() const { return N-1; }
char str[N];
};
template<unsigned expected_hash, fixed_string... s>
static consteval void VerifyHash()
{
(
[](auto){static_assert(hash(s.data(), s.size()) == expected_hash);}(s)
,...);
// The compiler mistakenly translates s.data() into s.data(&s)
// and then complains that the call is not valid, because
// the function expects 0 parameters and 1 "was provided".
}
void foo()
{
VerifyHash<5, "khaki", "plums">();
}
Compiler version:
g++-10 (Debian 10.2.1-6) 10.2.1 20210110
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/99895] Function parameters generated wrong in call to member of non-type template parameter in lambda
2021-04-03 8:56 [Bug c++/99895] New: Function parameters generated wrong in call to member of non-type template parameter in lambda bisqwit at iki dot fi
@ 2021-05-27 19:29 ` ppalka at gcc dot gnu.org
2022-01-27 16:02 ` cvs-commit at gcc dot gnu.org
2022-01-27 16:03 ` ppalka at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-05-27 19:29 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99895
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |ppalka at gcc dot gnu.org
Status|UNCONFIRMED |ASSIGNED
CC| |ppalka at gcc dot gnu.org
Ever confirmed|0 |1
Last reconfirmed| |2021-05-27
--- Comment #1 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Confirmed. Reduced:
struct fixed_string { consteval auto size() const { return 42; } };
template<fixed_string s>
static void VerifyHash() {
[](auto){ s.size(); };
}
void foo() { VerifyHash<{}>(); }
Declaring size() constexpr instead of consteval makes us accept.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/99895] Function parameters generated wrong in call to member of non-type template parameter in lambda
2021-04-03 8:56 [Bug c++/99895] New: Function parameters generated wrong in call to member of non-type template parameter in lambda bisqwit at iki dot fi
2021-05-27 19:29 ` [Bug c++/99895] " ppalka at gcc dot gnu.org
@ 2022-01-27 16:02 ` cvs-commit at gcc dot gnu.org
2022-01-27 16:03 ` ppalka at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-01-27 16:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99895
--- 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:dec8d0e5fa00ceb2ded78b8a3eba8976d860a90e
commit r12-6897-gdec8d0e5fa00ceb2ded78b8a3eba8976d860a90e
Author: Patrick Palka <ppalka@redhat.com>
Date: Thu Jan 27 10:56:49 2022 -0500
c++: non-dependent immediate member fn call [PR99895]
Here we're emitting a bogus error during ahead of time evaluation of a
non-dependent immediate member function call such as a.f(args) because
the defacto templated form for such a call is (a.f)(args) but we're
trying to evaluate it using the intermediate CALL_EXPR built by
build_over_call, which has the non-member form f(a, args). The defacto
member form is built in build_new_method_call, so it seems we should
handle the immediate call there instead, or perhaps make build_over_call
build the correct form in the first place.
Giiven that there are many spots other than build_new_method_call that
call build_over_call for member functions, e.g. build_op_call, this
patch takes the latter approach.
In passing, this patch makes us avoid wrapping PARM_DECL in
NON_DEPENDENT_EXPR for benefit of the third testcase below.
PR c++/99895
gcc/cp/ChangeLog:
* call.cc (build_over_call): For a non-dependent member call,
build up a CALL_EXPR using a COMPONENT_REF callee, as in
build_new_method_call.
* pt.cc (build_non_dependent_expr): Don't wrap PARM_DECL either.
* tree.cc (build_min_non_dep_op_overload): Adjust accordingly
after the build_over_call change.
gcc/ChangeLog:
* tree.cc (build_call_vec): Add const to second parameter.
* tree.h (build_call_vec): Likewise.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/consteval-memfn1.C: New test.
* g++.dg/cpp2a/consteval-memfn2.C: New test.
* g++.dg/cpp2a/consteval28.C: New test.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/99895] Function parameters generated wrong in call to member of non-type template parameter in lambda
2021-04-03 8:56 [Bug c++/99895] New: Function parameters generated wrong in call to member of non-type template parameter in lambda bisqwit at iki dot fi
2021-05-27 19:29 ` [Bug c++/99895] " ppalka at gcc dot gnu.org
2022-01-27 16:02 ` cvs-commit at gcc dot gnu.org
@ 2022-01-27 16:03 ` ppalka at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-01-27 16:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99895
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
Target Milestone|--- |12.0
--- Comment #3 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for GCC 12, thanks for the bug report.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-01-27 16:03 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-03 8:56 [Bug c++/99895] New: Function parameters generated wrong in call to member of non-type template parameter in lambda bisqwit at iki dot fi
2021-05-27 19:29 ` [Bug c++/99895] " ppalka at gcc dot gnu.org
2022-01-27 16:02 ` cvs-commit at gcc dot gnu.org
2022-01-27 16:03 ` 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).