public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "ppalka at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/109277] [13 Regression] type_traits:1417:30: error: invalid use of incomplete type ‘class v8::internal::WasmArray’
Date: Sat, 25 Mar 2023 14:20:05 +0000	[thread overview]
Message-ID: <bug-109277-4-uCJOhrRoZI@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-109277-4@http.gcc.gnu.org/bugzilla/>

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ppalka at gcc dot gnu.org

--- Comment #9 from Patrick Palka <ppalka at gcc dot gnu.org> ---
AFAICT the trait instantiation is legitimate, and this appears to be UB, here's
a boiled down testcase:

#include <tuple>
#include <type_traits>

struct Object;
struct MaybeObject;
struct WasmArray;

template<class T, class U>
struct is_subtype {
  static const bool value =
      std::is_base_of<U, T>::value || (std::is_same<U, MaybeObject>::value &&
                                       std::is_convertible<T, Object>::value);
};

template<class T>
struct TNode {
  TNode();

  template<class U, typename = std::enable_if_t<is_subtype<U, T>::value>>
  TNode(const TNode<U>&); // #1

  TNode(const TNode&);    // #2
};

std::tuple<TNode<WasmArray>> node;

The instantiation of std::is_convertible<WasmArray, Object> happens when
synthesizing tuple<TNode<WasmArray>> defaulted move constructor, for which we
need to perform overload resolution of TNode's constructors with a TNode&&
argument, and when considering the template candidate #1 we need to instantiate
its default template argument which entails instantiation of is_convertible.

In GCC 12 is_convertible for an incomplete type would silently return false. 
In GCC 13 the new built-in __is_convertible diagnoses this UB situation as a
hard error.  Clang's __is_convertible behaves like GCC 12's is_convertible it
seems.

One fix is to define a move constructor for TNode, which causes GCC's perfect
candidate optimization (r11-7287-g187d0d5871b1fa) to kick in and avoid
considering the template candidate #1.  Another fix is to use
std::conjunction/disjunction in is_subtype so that the condition properly
short-circuits (is_base_of<T, T> is true even for incomplete T).

  parent reply	other threads:[~2023-03-25 14:20 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-24 18:54 [Bug c++/109277] New: " marxin at gcc dot gnu.org
2023-03-24 18:54 ` [Bug c++/109277] " marxin at gcc dot gnu.org
2023-03-24 20:14 ` pinskia at gcc dot gnu.org
2023-03-24 20:20 ` [Bug libstdc++/109277] " pinskia at gcc dot gnu.org
2023-03-24 20:35 ` [Bug c++/109277] " pinskia at gcc dot gnu.org
2023-03-24 20:43 ` pinskia at gcc dot gnu.org
2023-03-24 20:47 ` pinskia at gcc dot gnu.org
2023-03-24 20:49 ` pinskia at gcc dot gnu.org
2023-03-24 20:53 ` pinskia at gcc dot gnu.org
2023-03-24 21:03 ` pinskia at gcc dot gnu.org
2023-03-24 21:07 ` redi at gcc dot gnu.org
2023-03-25 14:20 ` ppalka at gcc dot gnu.org [this message]
2023-03-25 14:30 ` ppalka at gcc dot gnu.org
2023-03-27  7:06 ` rguenth at gcc dot gnu.org
2023-04-04  3:33 ` jason at gcc dot gnu.org
2023-04-13 15:41 ` jason at gcc dot gnu.org
2023-04-13 18:59 ` cvs-commit at gcc dot gnu.org
2023-04-13 19:06 ` jason at gcc dot gnu.org

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=bug-109277-4-uCJOhrRoZI@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).