[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 5 10:32:09 PST 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Charalampos Mitrodimas (charmitro)
<details>
<summary>Changes</summary>
Warning '-Wundefined-func-template' incorrectly indicates that no definition is available for a pure virtual function. However, a definition is not needed for a pure virtual function.
Fixes #<!-- -->74016
---
Full diff: https://github.com/llvm/llvm-project/pull/74510.diff
2 Files Affected:
- (modified) clang/lib/Sema/SemaTemplateInstantiateDecl.cpp (+2-1)
- (added) clang/test/SemaTemplate/instantiate-pure-virtual-function.cpp (+20)
``````````diff
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index d768bb72e07c0..0850b2d64b632 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4952,7 +4952,8 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
std::make_pair(Function, PointOfInstantiation));
} else if (TSK == TSK_ImplicitInstantiation) {
if (AtEndOfTU && !getDiagnostics().hasErrorOccurred() &&
- !getSourceManager().isInSystemHeader(PatternDecl->getBeginLoc())) {
+ !getSourceManager().isInSystemHeader(PatternDecl->getBeginLoc()) &&
+ !Function->isVirtualAsWritten()) {
Diag(PointOfInstantiation, diag::warn_func_template_missing)
<< Function;
Diag(PatternDecl->getLocation(), diag::note_forward_template_decl);
diff --git a/clang/test/SemaTemplate/instantiate-pure-virtual-function.cpp b/clang/test/SemaTemplate/instantiate-pure-virtual-function.cpp
new file mode 100644
index 0000000000000..7ae323343330e
--- /dev/null
+++ b/clang/test/SemaTemplate/instantiate-pure-virtual-function.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wundefined-func-template %s
+// expected-no-diagnostics
+
+namespace PR74016 {
+ 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);
+ }
+};
``````````
</details>
https://github.com/llvm/llvm-project/pull/74510
More information about the cfe-commits
mailing list