<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/108655>108655</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang rejects the valid member function definition with typedefed retyrb type and global :: scope resolution operator
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
suikan4github
</td>
</tr>
</table>
<pre>
## Overview
Clang shows an error when a class member function definiton has both :
- Typedefed return type.
- Global :: scope resolutoin operator.
This problem is not found with GCC.
## Code to demonstrate
In the following code, uint32_t is typedefed inside stdint.h. Copy this code into foo.cpp.
```cpp
#include <stdint.h>
class foo {
public:
uint32_t bar(unsigned int a);
unsigned int baz(unsigned int a);
uint32_t qux(uint32_t a);
};
// Fail to compile with Clang 18.1.3 x86_64-pc-linux-gnu
uint32_t ::foo::bar(unsigned int a) { return a; }
// No problem if not using typdef.
unsigned int ::foo::baz(unsigned int a) { return a; }
// No problem if not using global scope resolution operator.
uint32_t foo::qux(uint32_t a) { return a; }
int main() {
foo my_foo;
return (my_foo.bar(0));
}
```
To reproduce the problem, run the following command.
```sh
takemasa@vm2204:~/git/sandbox$ clang-18 foo.cpp
foo.cpp:11:1: error: 'uint32_t' (aka 'unsigned int') is not a class, namespace, or enumeration
11 | uint32_t ::foo::bar(unsigned int a) { return a; }
| ^
1 error generated.
```
## Workaround
To avoid this problem, we should use non-typedefed return type in the function definiton.
```cpp
unsigned int ::foo::baz(unsigned int a) { return a; }
```
Or, we should not to use the global :: scope operator in the function definition.
```cpp
uint32_t foo::qux(uint32_t a) { return a; }
```
## Environment and version
- Ubuntu 22.04, 24.04
- Clang 18.1.8
```sh
takemasa@vm2204:~/git/sandbox$ clang-18 --version
Ubuntu clang version 18.1.8 (++20240731024944+3b5b5c1ec4a3-1~exp1~20240731145000.144)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
```
</pre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