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

* [Bug c++/94197] __is_constructible gives an access error
  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 ` redi at gcc dot gnu.org
  2020-03-16 17:36 ` ville.voutilainen at gmail dot com
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2020-03-16 17:11 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2020-03-16
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Reduced:

template<typename T>
  T&& declval() noexcept;

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<bool, typename T, typename Arg>
  struct __is_nt_constructible_impl
  : public false_type
  { };

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

template<typename T, typename Arg>
  using __is_nothrow_constructible_impl
    = __is_nt_constructible_impl<__is_constructible(T, Arg), T, Arg>;

template<typename T>
  struct __is_nothrow_copy_constructible_impl
  : public __is_nothrow_constructible_impl<T, const T&>
#ifdef FIX
    ::type
#endif
  { };

template<typename T>
  struct is_nothrow_copy_constructible
  : public __is_nothrow_copy_constructible_impl<T>
#ifndef FIX
    ::type
#endif
  { };

struct NType
{
  NType();
private:
  NType(const NType&);
};

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

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

* [Bug c++/94197] __is_constructible gives an access error
  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
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: ville.voutilainen at gmail dot com @ 2020-03-16 17:36 UTC (permalink / raw)
  To: gcc-bugs

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

Ville Voutilainen <ville.voutilainen at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ville.voutilainen at gmail dot com
           Assignee|unassigned at gcc dot gnu.org      |ville.voutilainen at gmail dot com
             Status|NEW                         |ASSIGNED

--- Comment #2 from Ville Voutilainen <ville.voutilainen at gmail dot com> ---
Mine.

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

* [Bug c++/94197] __is_constructible gives an access error
  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
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2020-03-16 21:44 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Patch posted: https://gcc.gnu.org/pipermail/gcc-patches/2020-March/542102.html

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

* [Bug c++/94197] __is_constructible gives an access error
  2020-03-16 16:06 [Bug c++/94197] New: __is_constructible gives an access error redi at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  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
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-03-17 15:03 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Ville Voutilainen <ville@gcc.gnu.org>:

https://gcc.gnu.org/g:887085be635101ae1fa16be8dcdbbe6b240b600b

commit r10-7219-g887085be635101ae1fa16be8dcdbbe6b240b600b
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date:   Tue Mar 17 16:38:25 2020 +0200

    c++: Fix access checks for __is_assignable and __is_constructible

    gcc/

    PR c++/94197
    * cp/method.c (assignable_expr): Use cp_unevaluated.
    (is_xible_helper): Push a non-deferred access check for
    the stub objects created by assignable_expr and constructible_expr.

    testsuite/

    PR c++/94197
    * g++.dg/ext/pr94197.C: New.

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

* [Bug c++/94197] __is_constructible gives an access error
  2020-03-16 16:06 [Bug c++/94197] New: __is_constructible gives an access error redi at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2020-03-17 15:03 ` cvs-commit at gcc dot gnu.org
@ 2021-09-30 15:01 ` ppalka at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-09-30 15:01 UTC (permalink / raw)
  To: gcc-bugs

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

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
   Target Milestone|---                         |10.0
                 CC|                            |ppalka at gcc dot gnu.org
         Resolution|---                         |FIXED

--- Comment #5 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for GCC 10+

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