<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/156255>156255</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang] Incorrect constexpr member function definition order dependency
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
pdimov
</td>
</tr>
</table>
<pre>
The following code
```
class X
{
public:
constexpr int f( int x ) const
{
return g( x );
}
private:
template<class T>
constexpr T g( T x ) const
{
return x;
}
};
constexpr int x = X().f( 1 );
```
is [rejected](https://godbolt.org/z/ox1E8nG7M) by Clang trunk (and all previous versions AFAICS) with
```
<source>:7:16: note: undefined function 'g<int>' cannot be used in a constant expression
7 | return g( x );
| ^
```
and in order to fix that, the definition of `g` needs to be moved above that of `f`.
But I don't think this order dependency is required by the standard, and [other](https://godbolt.org/z/qMe1dPMTM) [compilers](https://godbolt.org/z/dnrz95orn) accept the code.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyMlEuPozgQxz9N5VKaCOwYyIEDSTqrPrS00uYwV8AFeMfYjG0y6fn0KwPafuxh20I8TD1-9S_btfeqN0QliBOIy66ew2BdOUk12vuusfK1vA2EndXa_lKmx9ZKgqSCLNmupGp17T1-j7P5CZJqmhutWuBVnEkqRMTWGh_oMTlUJmAHrFheHgjsuP7cDNcIuA1HYXYG-2i_2AI__Wt4WcNPTt3rQB_SBRonvUyeV7gb8Kf_oNzWwLevYjy27Fvq_LJ-RwU-lPdA4Bf8DqwAdtwvxaZv8O-VUx5BnBz9TW0gCeICrBhCmHyshl2BXXsrG6vD3roe2PU3sKt9pE-F-SN_iczNK551bXoMbjY_EFhRG4m11jg5uis7e7yT88oaj9W1ej7_Fb1-qTB8IgF-9nZ2LUWheJUDr9IMeIXGLtribCR1ypDEbjZtUNYgsLwHflYmRCeWY1sbYwM2hLMnicpgvapam4BRHvIRZVM2R8jP-H-tfm-zDRBPn-hj0cqgdZIcBoudemAY6gDsjGEgXNDVAm07hCzpIUvQEEkfzRvC0d5JYt3YOy2em10HWbJfe3yaAz6jtAZYHjAMyvyId79llTSRkWTaV1QeHf2clSMZGxQBogSydjICRVgQJxsGcl9r-c8XSuWfL7el5SBOrR0npcn5r7lL434fhXUmutdtS1NYoOJW3u9kyeWRH-sdlWkusixLeCF2Q3k8sAMvGtEVicwEZQVJIUVe5HQULT-kO1WyhImk4GmapzwRe8nTJM9ExvOGU5d3cEhorJXea30fI89OeT9TmYqMCbHTdUPaLwcPY21cxcBYPINcGR2-NXPv4ZBo5YN_CxFU0MtptXqICz6b1jpHbXi3tUcaG3JvS_X9AvjUrt3sdPlJQhWGudm3dgR2jZm3x7fJ2bhVgV2XSjyw61bMvWT_BAAA__9Y5Zeu">