Issue 77104
Summary [Clang] Can not friend a function in root namespace with non-void return type
Labels clang
Assignees
Reporter Sh3Rm4n
    Compiler Explorer: https://godbolt.org/z/Gzhdo54W7

Clang is not able to friend a function, which lives in the root namespace. 

```cpp
#include <cstdint>

uint32_t friend_foo();

namespace n {
class bar {
    friend uint32_t ::friend_foo();
    void private_method() {}
};
}

uint32_t friend_foo() {
    n::bar b;
 b.private_method();
    return 0;
}
```

It has problems to swallow the `friend uint32_t ::friend_foo();` syntax. 

```
<source>:7:12: error: 'uint32_t' (aka 'unsigned int') is not a class, namespace, or enumeration
    7 |     friend uint32_t ::friend_foo();
      |   
```

Switching the return type to `void` removes the error. 

```diff
3c3
< uint32_t friend_foo();
---
> void friend_foo();
7c7
<     friend uint32_t ::friend_foo();
---
>     friend void ::friend_foo();
14c14
< uint32_t friend_foo() {
---
> void friend_foo() {
18,19d17
< 
<     return 0;
```

or moving the class and the function to the same namespace, so that the `::` prefix is not needed does remove the error.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to