public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/104141] New: Access to private member function from requires-clause accepted
@ 2022-01-20  7:14 fchelnokov at gmail dot com
  2022-01-21  3:56 ` [Bug c++/104141] nested requires statement causes access to private member function pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: fchelnokov at gmail dot com @ 2022-01-20  7:14 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 104141
           Summary: Access to private member function from requires-clause
                    accepted
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

This is invalid code:
```
class A{
   static void f();
};
static_assert( requires{ !requires{ A::f(); }; } );
```
and rejected by Clang and MSVC due to access to a private member function. But
GCC accepts it. Demo: https://gcc.godbolt.org/z/76jhYav4v

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

* [Bug c++/104141] nested requires statement causes access to private member function
  2022-01-20  7:14 [Bug c++/104141] New: Access to private member function from requires-clause accepted fchelnokov at gmail dot com
@ 2022-01-21  3:56 ` pinskia at gcc dot gnu.org
  2022-01-21  3:58 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-21  3:56 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Access to private member    |nested requires statement
                   |function from               |causes access to private
                   |requires-clause accepted    |member function

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I am not 100% up to speed on requires statment here but I would assume the
outer requires would cause the inner requires to be slient on access
violations.
E.g the following is accepted without error even:
class A{
   static void f();
};
template <class T> concept t =  requires{ T::f(); };
static_assert( !t<A> );
------ CUT ----
Likewise of this one where we don't have a depdent requires even (clang rejects
it but GCC/MSVC accept it):
class A{
   static void f();
};
template <class T> constexpr bool t =  requires{ A::f(); };
static_assert( !t<A> );
------ CUT ----
But GCC fails with this one but if the above is valid I don't see why the below
is not either:

class A{
   static void f();
};
static_assert( !requires{ A::f(); } );

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

* [Bug c++/104141] nested requires statement causes access to private member function
  2022-01-20  7:14 [Bug c++/104141] New: Access to private member function from requires-clause accepted fchelnokov at gmail dot com
  2022-01-21  3:56 ` [Bug c++/104141] nested requires statement causes access to private member function pinskia at gcc dot gnu.org
@ 2022-01-21  3:58 ` pinskia at gcc dot gnu.org
  2022-01-21  4:03 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-21  3:58 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note clang fails the static_assert with this one but that does not make sense
at all:
class A{
   static void f();
};
template <class T> concept t =  requires{ A::f(); };
static_assert( !t<A> );

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

* [Bug c++/104141] nested requires statement causes access to private member function
  2022-01-20  7:14 [Bug c++/104141] New: Access to private member function from requires-clause accepted fchelnokov at gmail dot com
  2022-01-21  3:56 ` [Bug c++/104141] nested requires statement causes access to private member function pinskia at gcc dot gnu.org
  2022-01-21  3:58 ` pinskia at gcc dot gnu.org
@ 2022-01-21  4:03 ` pinskia at gcc dot gnu.org
  2022-01-21  8:30 ` fchelnokov at gmail dot com
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-21  4:03 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Looks like clang does not always do access checking for static functions calls
inside requires. I know GCC has a bug there for dealing with caching in the
wrong context (I don't have the bug #).

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

* [Bug c++/104141] nested requires statement causes access to private member function
  2022-01-20  7:14 [Bug c++/104141] New: Access to private member function from requires-clause accepted fchelnokov at gmail dot com
                   ` (2 preceding siblings ...)
  2022-01-21  4:03 ` pinskia at gcc dot gnu.org
@ 2022-01-21  8:30 ` fchelnokov at gmail dot com
  2022-01-21  8:39 ` pinskia at gcc dot gnu.org
  2022-01-21  8:42 ` fchelnokov at gmail dot com
  5 siblings, 0 replies; 7+ messages in thread
From: fchelnokov at gmail dot com @ 2022-01-21  8:30 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Fedor Chelnokov <fchelnokov at gmail dot com> ---
In
```
template <class T> concept t =  requires{ A::f(); };
```
A::f() does not depend on template parameter, so the rules here are somewhat
different than in T::f(). A possible answer:
https://stackoverflow.com/a/70783451/7325599

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

* [Bug c++/104141] nested requires statement causes access to private member function
  2022-01-20  7:14 [Bug c++/104141] New: Access to private member function from requires-clause accepted fchelnokov at gmail dot com
                   ` (3 preceding siblings ...)
  2022-01-21  8:30 ` fchelnokov at gmail dot com
@ 2022-01-21  8:39 ` pinskia at gcc dot gnu.org
  2022-01-21  8:42 ` fchelnokov at gmail dot com
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-21  8:39 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Fedor Chelnokov from comment #4)
> A::f() does not depend on template parameter, so the rules here are somewhat
> different than in T::f(). A possible answer:
> https://stackoverflow.com/a/70783451/7325599

But clang is not rejecting it the following:

class A{
   static void f();
};
template <class T> concept t =  requires{ A::f(); };
static_assert( !t<A> );

By saying A::f() is private even, it literally sets the concept to false and
nothing else which is really really shocking.

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

* [Bug c++/104141] nested requires statement causes access to private member function
  2022-01-20  7:14 [Bug c++/104141] New: Access to private member function from requires-clause accepted fchelnokov at gmail dot com
                   ` (4 preceding siblings ...)
  2022-01-21  8:39 ` pinskia at gcc dot gnu.org
@ 2022-01-21  8:42 ` fchelnokov at gmail dot com
  5 siblings, 0 replies; 7+ messages in thread
From: fchelnokov at gmail dot com @ 2022-01-21  8:42 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Fedor Chelnokov <fchelnokov at gmail dot com> ---
I agree that Clang behavior here might be wrong. Submitted
https://github.com/llvm/llvm-project/issues/53334

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

end of thread, other threads:[~2022-01-21  8:42 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-20  7:14 [Bug c++/104141] New: Access to private member function from requires-clause accepted fchelnokov at gmail dot com
2022-01-21  3:56 ` [Bug c++/104141] nested requires statement causes access to private member function pinskia at gcc dot gnu.org
2022-01-21  3:58 ` pinskia at gcc dot gnu.org
2022-01-21  4:03 ` pinskia at gcc dot gnu.org
2022-01-21  8:30 ` fchelnokov at gmail dot com
2022-01-21  8:39 ` pinskia at gcc dot gnu.org
2022-01-21  8:42 ` fchelnokov at gmail dot com

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).