public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/108788] New: Lookup of injected class name should be type-dependent
@ 2023-02-14 16:33 m.cencora at gmail dot com
  2023-02-14 20:12 ` [Bug c++/108788] " pinskia at gcc dot gnu.org
  2023-05-19 18:24 ` ppalka at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: m.cencora at gmail dot com @ 2023-02-14 16:33 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108788
           Summary: Lookup of injected class name should be type-dependent
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: m.cencora at gmail dot com
  Target Milestone: ---

Following code fails to compile on any gcc version. Works on all clang
versions.

It looks like inside template function get_templ_base the lookup of
v.templ_base::a is done eagerly, and finds templ_base at the global scope, and
hence errors out because the template parameters are missing.
But at this point qualified name "templ_base::a" should be type-dependent, so
lookup should be delayed until template instantiation, where 'templ_base' is an
injected class name, so template paremeters shouldn't be required.

g++ -std=c++11

struct base
{
    int a = 1;
};

template <typename T>
struct templ_base
{
    int a = 2;
};

namespace bar
{

struct base2
{
    int a = 3;
};

template <typename T>
struct templ_base2
{
    int a = 4;
};


}

struct foo : base, bar::templ_base2<char>, templ_base<int>, bar::base2
{
    int base = 5;
    int templ_base = 6;
    int base2 = 7;
    int templ_base2 = 8;
    int a = 9;
};

static_assert(foo{}.base::a == 1, "");
static_assert(foo{}.templ_base::a == 2, "");
static_assert(foo{}.base2::a == 3, "");
static_assert(foo{}.templ_base2::a == 4, "");


template <typename T>
int get_base(T&& v)
{
    return v.base::a;
}

template <typename T>
int get_templ_base(T&& v)
{
    return v.templ_base::a; // fails in all gcc versions
}

template <typename T>
int get_base2(T&& v)
{
    return v.base2::a; // fails for gcc <= 11
}

template <typename T>
int get_templ_base2(T&& v)
{
    return v.templ_base2::a;  // fails for gcc <= 11
}

int a = get_base(foo{});
int b = get_templ_base(foo{});
int c = get_base2(foo{});
int d = get_templ_base2(foo{});

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

* [Bug c++/108788] Lookup of injected class name should be type-dependent
  2023-02-14 16:33 [Bug c++/108788] New: Lookup of injected class name should be type-dependent m.cencora at gmail dot com
@ 2023-02-14 20:12 ` pinskia at gcc dot gnu.org
  2023-05-19 18:24 ` ppalka at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-02-14 20:12 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I suspect this is related to the C++ paper:
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1787r6.html

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

* [Bug c++/108788] Lookup of injected class name should be type-dependent
  2023-02-14 16:33 [Bug c++/108788] New: Lookup of injected class name should be type-dependent m.cencora at gmail dot com
  2023-02-14 20:12 ` [Bug c++/108788] " pinskia at gcc dot gnu.org
@ 2023-05-19 18:24 ` ppalka at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-05-19 18:24 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #2 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Partially fixed by r12-3643-g18b57c1d4a8777.  Reduced version of what we still
reject:

template <typename T>
struct templ_base { };

template <typename T>
int get_templ_base(T&& v)
{
    return v.templ_base::a; // fails in all gcc versions
}

<stdin>: In function ‘int get_templ_base(T&&)’:
<stdin>:7:14: error: ‘template<class T> struct templ_base’ used without
template arguments

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

end of thread, other threads:[~2023-05-19 18:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-14 16:33 [Bug c++/108788] New: Lookup of injected class name should be type-dependent m.cencora at gmail dot com
2023-02-14 20:12 ` [Bug c++/108788] " pinskia at gcc dot gnu.org
2023-05-19 18:24 ` 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).