diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2022-09-23 22:04:24 +0100 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2022-09-23 23:22:37 +0100 |
commit | 5924c7d584640665db174c7545ae6c2b784af27c (patch) | |
tree | d7c52f3da14059c9ea563635ef85c0fb72f4efee | |
parent | 71c828f84572d933979468baf2cf744180258ee4 (diff) | |
download | gcc-5924c7d584640665db174c7545ae6c2b784af27c.zip gcc-5924c7d584640665db174c7545ae6c2b784af27c.tar.gz gcc-5924c7d584640665db174c7545ae6c2b784af27c.tar.bz2 |
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.
-rw-r--r-- | libstdc++-v3/testsuite/20_util/is_assignable/requirements/access.cc | 22 |
1 files changed, 22 insertions, 0 deletions
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 0000000..a96fba6 --- /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 +} |