<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/130266>130266</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
GCC does not issue any warning when two function templates have identical parameters but different return types.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Denys619
</td>
</tr>
</table>
<pre>
GCC does not issue any warning when two function templates have identical parameters but different return types. This can lead to unexpected behavior and potential errors that are only caught at the point of invocation.
Steps to reproduce:
The following code compiles without warnings using g++ -Wall -Wextra -Wpedantic:
```
template <typename T>
void f(T x) {}
template <typename T>
int f(T y) {
return 0;
}
int main() {}
```
Expected behavior:
Either an error or at least a warning should be generated at the declaration stage.
Currently, the compiler only complains when f() is called, which might lead to silent issues in large codebases.
Tested on:
Clang 18.1.3
Possible solutions:
Introduce a warning (-Wtemplate-redefinition or similar) when such a case is detected.
Add a compiler diagnostic suggesting to rename one of the functions or modify the template parameters.
Additional notes:
This behavior is inconsistent with how function overloading normally works in C++, where functions with the same signature but different return types are not allowed.
Should this be reported as a bug or a feature request?
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy8VE1v-jgT_zTmMgIZBwgcOFBaHj23lbZSz0M8JN517KzHgfLtV-NA293D_7hSpUrEHv9eB5ldG4j2av2i1q8zHHMX0_6Vwp03y93sHO19_7_jEWwkhhAzOOaRAMMdbpiCCy3cOgqQbxEuY2iyiwEy9YPHTAwdXgmcpZBdgx4GTNhTpsRwHjNYd7lQopAhUR5TgHwfiBfw3jmGBgN4Qgs5whjoc6Amk4UzdXh1MQEGC0PMMho9UEoxMeQOM2AiiMHfocGx7TJghtwRDNGFDPECLlxjg4J0ofRB6cPvmQaWdxINKdqxIVUdpk_vHcEleh9vQrWJlqCJ_eA8Mdxc7uKYn0IwjCyHWmVelHmB-Qd6D_MP-swJYf4xkEXR4Wu22ujHnz48JQN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