Skip to content

friend definition makes function visible when it should not #39580

@ryanhaining

Description

@ryanhaining
Bugzilla Link 40233
Version trunk
OS Linux
CC @DougGregor,@zygoloid

Extended Description

Based on this stackoverflow question: https://stackoverflow.com/q/54055638/1013719

gcc correctly rejects the following, while clang accepts:

class Cls {
    friend void func(int) { }
    friend void ::func(int);
};

with:

error: ‘void func(int)’ has not been declared within ‘::’
     friend void ::func(int);
                 ^~
note: only here as a ‘friend’
     friend void func(int) { }
                 ^~~~

The friend definition should not make func visible by http://eel.is/c++draft/namespace.memdef#3.sentence-2

The friend declaration does not by itself make the name visible to unqualified lookup or qualified lookup.

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepts-invalidbugzillaIssues migrated from bugzillac++clang:frontendLanguage frontend issues, e.g. anything involving "Sema"

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions