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

--- Comment #5 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Simon Martin <simar...@gcc.gnu.org>:

https://gcc.gnu.org/g:b5a069203fc074ab75d994c4a7e0f2db6a0a00fd

commit r15-6991-gb5a069203fc074ab75d994c4a7e0f2db6a0a00fd
Author: Simon Martin <si...@nasilyan.com>
Date:   Sun Jan 5 10:36:47 2025 +0100

    c++: Friend classes don't shadow enclosing template class paramater
[PR118255]

    We currently reject the following code

    === code here ===
    template <int non_template> struct S { friend class non_template; };
    class non_template {};
    S<0> s;
    === code here ===

    While EDG agrees with the current behaviour, clang and MSVC don't (see
    https://godbolt.org/z/69TGaabhd), and I believe that this code is valid,
    since the friend clause does not actually declare a type, so it cannot
    shadow anything. The fact that we didn't error out if the non_template
    class was declared before S backs this up as well.

    This patch fixes this by skipping the call to check_template_shadow for
    hidden bindings.

            PR c++/118255

    gcc/cp/ChangeLog:

            * name-lookup.cc (pushdecl): Don't call check_template_shadow
            for hidden bindings.

    gcc/testsuite/ChangeLog:

            * g++.dg/lookup/pr99116-1.C: Adjust test expectation.
            * g++.dg/template/friend84.C: New test.

Reply via email to