llvm / llvm/llvm-project

[clang-tidy] `portability-template-virtual-member-function` warns about virtual method invoked via reference to base class

Open
#206,767 10 comments 0 reactions 0 assignees View on GitHub
clang-tidy enhancement question
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

I need guidance on what is the expected way to fix this warning.

https://godbolt.org/z/813shrrP7

```
:8:10: warning: unspecified virtual member function instantiation; the virtual member function is not instantiated but it might be with a different compiler [portability-template-virtual-member-function]
8 | void foo() override {}
| ^
:16:16: note: template instantiated here
16 | Impl v;
| ^
1 warning generated.
```

Imagine this code was in a header included by multiple translation units. Some translation units constructs `Wrapper` objects, some don't. Translation units that construct `Wrapper` won't have this warning, while others will.

All translation units compile, so the there is no concern of the project compiling on GCC/clang but not on MSVC (this was the rationale of the check according to https://github.com/llvm/llvm-project/issues/153155#issuecomment-3243348741).

Now I'm stuck with warnings in translation units that don't construct `Wrapper` objects.

Current trunk: bd6adfedc776c07caf158e59367d9c246c933510

Contributor guide

Open the contributing guide

Research direction

Start with the linked Godbolt reproduction and the clang-tidy check named in the title. Read the rationale in issue #153155 and inspect the check's existing behavior; done means establishing whether this warning is expected for translation units that do not construct Wrapper and documenting or correcting that behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.