https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126755

            Bug ID: 126755
           Summary: GCC rejects valid program involving overloaded
                    conversion operators
           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(afaik) is rejected by gcc,edg and msvc but accepted
by clang. https://godbolt.org/z/a7b9qzaTs

```
struct S {
    template<typename T>
    constexpr operator T()const    
    {
        return 10;
    }
    constexpr operator int()
    {
        return 4;
    }   
};
int main()
{
    constexpr S s;
    constexpr int i =  s.operator int(); //clang ok, gcc:no msvc:no
    int arr[i];
}
```
GCC says:
```
<source>: In function 'int main()':
<source>:22:38: error: passing 'const S' as 'this' argument discards qualifiers
[-fpermissive]
   22 |     constexpr int i =  s.operator int(); //clang ok, gcc:no msvc:no
      |                        ~~~~~~~~~~~~~~^~
<source>:10:15: note:   in call to 'constexpr S::operator int()'
   10 |     constexpr operator int()
      | 
```

Reply via email to