https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127015
Bug ID: 127015
Summary: GCC rejects valid explicit specialization of
conversion function inside class
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: jlame646 at gmail dot com
Target Milestone: ---
The following valid program is rejected by gcc, clang and msvc. Note this is
accepted by only edg. https://godbolt.org/z/1P75czEe8
```
struct S {
template<typename T>
constexpr operator T()
{
return 10;
}
//rejected by all compilers except EDG
template<>
constexpr operator int()
{
return 4;
}
};
/*accepted in all compilers
template<>
constexpr S::operator int()
{
return 4;
}
*/
int main()
{
S s;
int i = s;
i++;
}
```
This seems to be well-formed as per
https://eel.is/c++draft/temp.spec#temp.expl.spec-3
GCC says:
```
error: explicit specialization in non-namespace scope 'struct S'
9 | template<>
```