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

            Bug ID: 121297
           Summary: Gcc fails to compile code where scalar types for
                    non-type template parameters have virtual functions
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: familiebaumanns at gmail dot com
  Target Milestone: ---

Gcc fails to compile if the type of a non-type template parameter has virtual
functions (see: https://godbolt.org/z/rGdExEb7h):

```c++
class Foo{
    virtual void Bar(){
    }
};

template<Foo foo>
void XXX(){

}

int main(){
    constexpr static auto foo = Foo();
    XXX<foo>();
    return 0;
}
```

Error message:
```
<source>: In function 'int main()':
<source>:13:13: error: no matching function for call to 'XXX<foo>()'
   13 |     XXX<foo>();
      |     ~~~~~~~~^~
<source>:13:13: note: there is 1 candidate
<source>:7:6: note: candidate 1: 'template<Foo foo> void XXX()'
    7 | void XXX(){
      |      ^~~
<source>:7:6: note: template argument deduction/substitution failed:
<source>:13:13: error: '((& Foo::_ZTV3Foo) + 16)' is not a valid template
argument for 'int (**)(...)' because it is not the address of a variable
   13 |     XXX<foo>();
      |     ~~~~~~~~^~
Compiler returned: 1
```

See stackoverflow:
https://stackoverflow.com/questions/79717935/are-virtual-functions-allowed-for-scalar-types-used-as-non-type-template-argum/79718208#79718208

Reply via email to