public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/94197] New: __is_constructible gives an access error
@ 2020-03-16 16:06 redi at gcc dot gnu.org
  2020-03-16 17:11 ` [Bug c++/94197] " redi at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2020-03-16 16:06 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 94197
           Summary: __is_constructible gives an access error
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

This fails to compile, but I think should be valid:

template<typename _Tp, typename _Up = _Tp&&>
  _Up
  __declval(int);

template<typename _Tp>
  _Tp
  __declval(long);

template<typename _Tp>
  auto declval() noexcept -> decltype(__declval<_Tp>(0));

template<bool B>
struct bool_constant
{
  static constexpr bool value = B;
  using type = bool_constant;
};

using true_type = bool_constant<true>;
using false_type = bool_constant<false>;

template<typename...> using __void_t = void;


template<typename _Tp, typename = void>
  struct __is_referenceable
  : public false_type
  { };

template<typename _Tp>
  struct __is_referenceable<_Tp, __void_t<_Tp&>>
  : public true_type
  { };


template<bool, typename _Tp, typename... _Args>
  struct __is_nt_constructible_impl
  : public false_type
  { };

template<typename _Tp, typename... _Args>
  struct __is_nt_constructible_impl<true, _Tp, _Args...>
  : public bool_constant<noexcept(_Tp(declval<_Args>()...))>
  { };

template<typename _Tp, typename _Arg>
  struct __is_nt_constructible_impl<true, _Tp, _Arg>
  : public bool_constant<noexcept(static_cast<_Tp>(declval<_Arg>()))>
  { };

template<typename _Tp>
  struct __is_nt_constructible_impl<true, _Tp>
  : public bool_constant<noexcept(_Tp())>
  { };

template<typename _Tp, typename... _Args>
  using __is_nothrow_constructible_impl
    = __is_nt_constructible_impl<__is_constructible(_Tp, _Args...),
                                 _Tp, _Args...>;

/// is_nothrow_constructible
template<typename _Tp, typename... _Args>
  struct is_nothrow_constructible
  : public __is_nothrow_constructible_impl<_Tp, _Args...>::type
  {
  };

/// is_nothrow_default_constructible
template<typename _Tp>
  struct is_nothrow_default_constructible
  : public __is_nothrow_constructible_impl<_Tp>::type
  {
  };

template<typename _Tp, bool = __is_referenceable<_Tp>::value>
  struct __is_nothrow_copy_constructible_impl;

template<typename _Tp>
  struct __is_nothrow_copy_constructible_impl<_Tp, false>
  : public false_type { };

template<typename _Tp>
  struct __is_nothrow_copy_constructible_impl<_Tp, true>
  : public __is_nothrow_constructible_impl<_Tp, const _Tp&>
  { };

/// is_nothrow_copy_constructible
template<typename _Tp>
  struct is_nothrow_copy_constructible
  : public __is_nothrow_copy_constructible_impl<_Tp>::type
  {
  };

struct NType
{
NType(int);
~NType();
int i;
private:
NType(const NType&);
NType& operator=(const NType&);
int i2;
};

static_assert( !is_nothrow_copy_constructible<NType>::value, "" );



cons.cc: In substitution of 'template<class _Tp, class ... _Args> using
__is_nothrow_constructible_impl =
__is_nt_constructible_impl<__is_constructible(_Tp), _Tp, _Args ...> [with _Tp =
NType; _Args = {const NType&}]':
cons.cc:84:12:   required from 'struct
__is_nothrow_copy_constructible_impl<NType, true>'
cons.cc:90:12:   required from 'struct is_nothrow_copy_constructible<NType>'
cons.cc:106:53:   required from here
cons.cc:59:36: error: 'NType::NType(const NType&)' is private within this
context
   59 |       = __is_nt_constructible_impl<__is_constructible(_Tp, _Args...),
      |                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cons.cc:101:3: note: declared private here
  101 |   NType(const NType&);
      |   ^~~~~
cons.cc: In instantiation of 'struct __is_nt_constructible_impl<true, NType,
const NType&>':
cons.cc:84:12:   required from 'struct
__is_nothrow_copy_constructible_impl<NType, true>'
cons.cc:90:12:   required from 'struct is_nothrow_copy_constructible<NType>'
cons.cc:106:53:   required from here
cons.cc:49:37: error: 'NType::NType(const NType&)' is private within this
context
   49 |     : public bool_constant<noexcept(static_cast<_Tp>(declval<_Arg>()))>
      |                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cons.cc:101:3: note: declared private here
  101 |   NType(const NType&);
      |   ^~~~~


The __is_constructible expression should evaluate to false, without giving an
error.



If the testcase is modified like this, it works:

--- cons.cc~    2020-03-16 16:06:11.415546445 +0000
+++ cons.cc     2020-03-16 16:06:13.419555634 +0000
@@ -81,13 +81,13 @@

 template<typename _Tp>
   struct __is_nothrow_copy_constructible_impl<_Tp, true>
-  : public __is_nothrow_constructible_impl<_Tp, const _Tp&>
+  : public __is_nothrow_constructible_impl<_Tp, const _Tp&>::type
   { };

 /// is_nothrow_copy_constructible
 template<typename _Tp>
   struct is_nothrow_copy_constructible
-  : public __is_nothrow_copy_constructible_impl<_Tp>::type
+  : public __is_nothrow_copy_constructible_impl<_Tp>
   {
   };

This doesn't make any sense to me.

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

end of thread, other threads:[~2021-09-30 15:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-16 16:06 [Bug c++/94197] New: __is_constructible gives an access error redi at gcc dot gnu.org
2020-03-16 17:11 ` [Bug c++/94197] " redi at gcc dot gnu.org
2020-03-16 17:36 ` ville.voutilainen at gmail dot com
2020-03-16 21:44 ` redi at gcc dot gnu.org
2020-03-17 15:03 ` cvs-commit at gcc dot gnu.org
2021-09-30 15:01 ` 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).