Inline friend-defined functions when the class is in a namespace

Open
#1,935 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
cpp
Domain
tooling

Research direction

Start by reproducing the namespace-scoped friend function with CppSharp and options.CheckSymbols enabled. Inspect the generated symbols file and the handling of the friend-defined function declaration. Done means the generated declaration and function pointer use the NS namespace and compile successfully.

Written by the indexing model from the issue text.

Description

namespace NS
{
    struct A
    {
        friend void foo(A) {}
    };
}

CppSharp chokes on this with `options.CheckSymbols = true;.

It generates the following line in the symbols file, which doesn't compile:

void foo(struct NS::A);
void (*_1)(struct NS::A) = &NS::foo;

Here foo should be declared in namespace NS, but gets declared in the global namespace.

This results in:

error: no member named 'foo' in namespace 'NS'
Dominant language
C#
Stars
3.4k
Forks
541
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from mono/CppSharp

All issues in mono/CppSharp

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.