public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "pinskia at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/110580] [14 Regression] gcc fails to typecheck nix-2.16.1 source: error: invalid initialization of reference of type Date: Sun, 09 Jul 2023 18:26:49 +0000 [thread overview] Message-ID: <bug-110580-4-cYF1S0IAE0@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-110580-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110580 --- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Reduced all the way: ``` template <typename _Tp> struct remove_reference { using type = __remove_reference(_Tp); }; template <typename _Tp> using remove_reference_t = typename remove_reference<_Tp>::type; template <typename _Tp, typename _Up> inline constexpr bool is_same_v = __is_same(_Tp, _Up); template <typename _Key> class s3 { public: template <typename _Up, typename _Vp = remove_reference_t<_Up>> static constexpr bool __usable_key = is_same_v<const _Vp, const _Key>; template <typename _Args> void f(_Args __args, int t) { if constexpr (__usable_key<_Args>) { const _Key &__k = __args; } } }; struct s0 {}; struct s1 {}; s1 g(); void createMember(int member, s3<s0> &children) { children.f(g(), member); } ``` Or if using the internal type_traits is bad idea here is better testcase: ``` #include <type_traits> using namespace std; template <typename _Key> class s3 { public: template <typename _Up, typename _Vp = remove_reference_t<_Up>> static constexpr bool __usable_key = is_same_v<const _Vp, const _Key>; template <typename _Args> void f(_Args __args, int t) { if constexpr (__usable_key<_Args>) { const _Key &__k = __args; } } }; struct s0 {}; struct s1 {}; s1 g(); void createMember(int member, s3<s0> &children) { children.f(g(), member); } ``` Here is a testcase using static assert rather than if constexpr: ``` #include <type_traits> using namespace std; template <typename _Key> class s3 { public: template <typename _Up, typename _Vp = remove_reference_t<_Up>> static constexpr bool __usable_key = is_same_v<const _Vp, const _Key>; template <typename _Args> void f(_Args __args, int t) { static_assert(!__usable_key<_Args>); } }; struct s0 {}; struct s1 {}; s1 g(); void createMember(int member, s3<s0> &children) { children.f(g(), member); } ```
next prev parent reply other threads:[~2023-07-09 18:26 UTC|newest] Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-07-06 21:46 [Bug c++/110580] New: " slyfox at gcc dot gnu.org 2023-07-07 6:53 ` [Bug c++/110580] " rguenth at gcc dot gnu.org 2023-07-09 7:02 ` pinskia at gcc dot gnu.org 2023-07-09 15:56 ` pinskia at gcc dot gnu.org 2023-07-09 18:26 ` pinskia at gcc dot gnu.org [this message] 2023-07-09 18:37 ` pinskia at gcc dot gnu.org 2023-07-10 5:47 ` pinskia at gcc dot gnu.org 2023-07-10 5:53 ` pinskia at gcc dot gnu.org 2023-07-10 18:24 ` ppalka at gcc dot gnu.org 2023-07-11 14:06 ` cvs-commit at gcc dot gnu.org 2023-07-11 14:06 ` ppalka at gcc dot gnu.org 2023-07-11 19:02 ` slyfox 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-110580-4-cYF1S0IAE0@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: linkBe 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).