Bug 109420 - [13 Regression] lookup of 'struct T::X' at instantiation time does not ignore non-type bindings of 'X' since r13-6098-g46711ff8e60d64
Summary: [13 Regression] lookup of 'struct T::X' at instantiation time does not ignore...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 13.0
: P1 normal
Target Milestone: 13.0
Assignee: Patrick Palka
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2023-04-05 13:53 UTC by Patrick Palka
Modified: 2025-10-07 17:10 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work: 12.2.0
Known to fail: 13.0
Last reconfirmed: 2023-04-05 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Patrick Palka 2023-04-05 13:53:01 UTC
struct A {
  struct X { };
  int X;
};

template<class T>
void f() {
  struct T::X x;
}

template void f<A>();

<stdin>: In instantiation of ‘void f() [with T = A]’:
<stdin>:11:20:   required from here
<stdin>:8:15: error: ‘typename A::X’ names ‘int A::X’, which is not a type
Comment 1 Patrick Palka 2023-04-05 13:54:07 UTC
Started with r13-6098-g46711ff8e60d64
Comment 2 Patrick Palka 2023-04-12 15:34:17 UTC
FWIW a candidate fix has been posted at https://gcc.gnu.org/pipermail/gcc-patches/2023-April/615250.html and will hopefully get reviewed/pushed later this week
Comment 3 GCC Commits 2023-04-13 20:02:35 UTC
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:50dc52e853ff267ad1f4c98571c262017b0536f8

commit r13-7173-g50dc52e853ff267ad1f4c98571c262017b0536f8
Author: Patrick Palka <ppalka@redhat.com>
Date:   Thu Apr 13 16:02:21 2023 -0400

    c++: 'typename T::X' vs 'struct T::X' lookup [PR109420]
    
    r13-6098-g46711ff8e60d64 made make_typename_type no longer ignore
    non-types during the lookup, unless the TYPENAME_TYPE in question was
    followed by the :: scope resolution operator.  But there is another
    exception to this rule: we need to ignore non-types during the lookup
    also if the TYPENAME_TYPE was named with a tag other than 'typename',
    such as 'struct' or 'enum', since in that case we're dealing with an
    elaborated-type-specifier and so [basic.lookup.elab] applies.  This
    patch implements this additional exception.
    
            PR c++/109420
    
    gcc/cp/ChangeLog:
    
            * decl.cc (make_typename_type): Also ignore non-types during the
            lookup if tag_type corresponds to an elaborated-type-specifier.
            * pt.cc (tsubst) <case TYPENAME_TYPE>: Pass class_type or
            enum_type as tag_type to make_typename_type accordingly instead
            of always passing typename_type.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/template/typename27.C: New test.
Comment 4 Patrick Palka 2023-04-13 20:04:19 UTC
Fixed.