public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc r13-2826] libstdc++: Add test for type traits not having friend access
Date: Sat, 24 Sep 2022 00:07:28 +0000 (GMT)	[thread overview]
Message-ID: <20220924000728.4582A3858419@sourceware.org> (raw)

https://gcc.gnu.org/g:5924c7d584640665db174c7545ae6c2b784af27c

commit r13-2826-g5924c7d584640665db174c7545ae6c2b784af27c
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Fri Sep 23 22:04:24 2022 +0100

    libstdc++: Add test for type traits not having friend access
    
    This ensures that the std::is_assignable and std::is_assignable_v
    traits are evaluated "in a context unrelated" to the argument types.
    
    libstdc++-v3/ChangeLog:
    
            * testsuite/20_util/is_assignable/requirements/access.cc:
            New test.

Diff:
---
 .../20_util/is_assignable/requirements/access.cc   | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/libstdc++-v3/testsuite/20_util/is_assignable/requirements/access.cc b/libstdc++-v3/testsuite/20_util/is_assignable/requirements/access.cc
new file mode 100644
index 00000000000..a96fba654cd
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/is_assignable/requirements/access.cc
@@ -0,0 +1,22 @@
+// { dg-do compile { target c++11 } }
+
+#include <type_traits>
+
+class S {
+  operator int();
+  friend void g(); // #1
+};
+
+void
+g()
+{
+  int i = 0;
+  S s;
+  i = s; // this works, because we're inside a friend.
+
+  // But the traits are evaluated in "a context unrelated to either type".
+  static_assert( ! std::is_assignable<int&, S>::value, "unfriendly");
+#if __cplusplus >= 201703L
+  static_assert( ! std::is_assignable_v<int&, S>, "unfriendly");
+#endif
+}

                 reply	other threads:[~2022-09-24  0:07 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220924000728.4582A3858419@sourceware.org \
    --to=redi@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).