Skip to content

-Wundefined-func-template warns that no definition is available for a pure virtual function #74016

@ahatanak

Description

@ahatanak

The warning seems incorrect as B::bar is pure virtual and its definition isn't needed.

$ cat test.cpp
template <typename T> class B {
public:
  constexpr void foo(const T &) { bar(1); }
  virtual constexpr void bar(unsigned int) = 0;
};

template <typename T> class D : public B<T> {
public:
  constexpr void bar(unsigned int) override {}
};

void test() {
  auto t = D<int>();
  t.foo(0);
}
$ clang++ -std=c++20 test.cpp -Wundefined-func-template -c
test.cpp:4:35: warning: instantiation of function 'B<int>::bar' required here, but no definition is available [-Wundefined-func-template]
  constexpr void foo(const T &) { bar(1); }
                                  ^
test.cpp:5:26: note: forward declaration of template entity is here
  virtual constexpr void bar(unsigned int) = 0;
                         ^
test.cpp:4:35: note: add an explicit instantiation declaration to suppress this warning if 'B<int>::bar' is explicitly instantiated in another translation unit
  constexpr void foo(const T &) { bar(1); }
                                  ^
1 warning generated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerconfirmedVerified by a second partyfalse-positiveWarning fires when it should notgood first issuehttps://github.com/llvm/llvm-project/contribute

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions