public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/107439] New: use of static member function in requires-expression depends on declaration order
@ 2022-10-27 16:22 jwjagersma at gmail dot com
2022-10-28 14:01 ` [Bug c++/107439] " ppalka at gcc dot gnu.org
2022-10-28 14:27 ` ppalka at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: jwjagersma at gmail dot com @ 2022-10-27 16:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107439
Bug ID: 107439
Summary: use of static member function in requires-expression
depends on declaration order
Product: gcc
Version: 13.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: jwjagersma at gmail dot com
Target Milestone: ---
The following example fails to compile, as g++ complains that a declaration of
'check' is not available. Reordering it so that 'check' is declared before
its use in the requires-expression makes it work. This seems inconsistent, as
member functions are normally expected to be usable anywhere within the class
definition.
$ cat requires-memfn.cpp
struct A
{
template<typename T> requires (check<T>())
auto func(T) { }
template<typename T>
static consteval bool check() { return true; }
};
$ g++ -std=c++20 requires-memfn.cpp
requires-memfn.cpp:3:34: error: there are no arguments to ‘check’ that depend
on a template parameter, so a declaration of ‘check’
must be available [-fpermissive]
3 | template<typename T> requires (check<T>())
| ^~~~~~~~
requires-memfn.cpp:3:34: note: (if you use ‘-fpermissive’, G++ will accept
your code, but allowing the use of an undeclared name is deprecated)
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/107439] use of static member function in requires-expression depends on declaration order
2022-10-27 16:22 [Bug c++/107439] New: use of static member function in requires-expression depends on declaration order jwjagersma at gmail dot com
@ 2022-10-28 14:01 ` ppalka at gcc dot gnu.org
2022-10-28 14:27 ` ppalka at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-10-28 14:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107439
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |ppalka at gcc dot gnu.org
--- Comment #1 from Patrick Palka <ppalka at gcc dot gnu.org> ---
> This seems inconsistent, as member functions are normally expected to be usable anywhere within the class definition.
IIUC associated constraints are part of the function signature and thus aren't
late parsed like the function body is, so later-declared members aren't
generally usable in a constraint.
Interestingly, if we add a dummy argument to 'check' then we accept the call
(and treat it as an ADL-enabled call to an unknown function template where
unqualified lookup found nothing):
struct A
{
template<typename T> requires (check<T>(0))
auto func(T) { }
template<typename T>
static consteval bool check(0) { return true; }
};
But if we then try to actually use func, its constraint will always fail due to
'check' not being visible at the point of use (since associated constraints
aren't late-parsed):
int main() {
A a;
a.func(0); // error: ‘check’ was not declared in this scope, and no
declarations were found by argument-dependent lookup at the point of
instantiation
}
This behavior (for the modified testcase) is correct AFAICT (Clang behaves the
same).
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/107439] use of static member function in requires-expression depends on declaration order
2022-10-27 16:22 [Bug c++/107439] New: use of static member function in requires-expression depends on declaration order jwjagersma at gmail dot com
2022-10-28 14:01 ` [Bug c++/107439] " ppalka at gcc dot gnu.org
@ 2022-10-28 14:27 ` ppalka at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-10-28 14:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107439
--- Comment #2 from Patrick Palka <ppalka at gcc dot gnu.org> ---
So the question is if in C++20 mode we're allowed to reject ahead of time a
call to an unknown template-id with dependent template arguments and no
function arguments (as in the original testcase):
template<class T>
void f() {
g<T>(); // OK? gcc rejects, clang/msvc accept
}
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-10-28 14:27 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-27 16:22 [Bug c++/107439] New: use of static member function in requires-expression depends on declaration order jwjagersma at gmail dot com
2022-10-28 14:01 ` [Bug c++/107439] " ppalka at gcc dot gnu.org
2022-10-28 14:27 ` 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).