[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2024-04-09 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman closed 
https://github.com/llvm/llvm-project/pull/74510
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2024-04-09 Thread Charalampos Mitrodimas via cfe-commits

charmitro wrote:

> LGTM! Do you need someone to land this on your behalf?

I don't have commit rights. If I remember correctly from when LLVM used 
Phabricator (reviews.llvm.org) you'd need my name & e-address. If that's so,
`Charalampos Mitrodimas `

https://github.com/llvm/llvm-project/pull/74510
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2024-04-09 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman approved this pull request.

LGTM! Do you need someone to land this on your behalf?

https://github.com/llvm/llvm-project/pull/74510
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2024-04-05 Thread Charalampos Mitrodimas via cfe-commits

https://github.com/charmitro updated 
https://github.com/llvm/llvm-project/pull/74510

>From 0348c138e5a4295d86defbe40259105b64703d13 Mon Sep 17 00:00:00 2001
From: Charalampos Mitrodimas 
Date: Tue, 5 Dec 2023 11:46:56 +0200
Subject: [PATCH] [clang] Disable missing definition warning on pure virtual
 functions

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

Signed-off-by: Charalampos Mitrodimas 
---
 clang/docs/ReleaseNotes.rst   |  4 ++
 clang/lib/Sema/SemaExpr.cpp   |  6 +-
 .../instantiate-pure-virtual-function.cpp | 67 +++
 3 files changed, 75 insertions(+), 2 deletions(-)
 create mode 100644 
clang/test/SemaTemplate/instantiate-pure-virtual-function.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 28e8ddb3c41c3e..15738b3fa03739 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -346,6 +346,10 @@ Improvements to Clang's time-trace
 
 Bug Fixes in This Version
 -
+- Clang's ``-Wundefined-func-template`` no longer warns on pure virtual
+  functions.
+  (`#74016 `_)
+
 - Fixed missing warnings when comparing mismatched enumeration constants
   in C (`#29217 `).
 
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 6b2eb245d58263..33f8a7fdb4d903 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -18980,8 +18980,10 @@ void Sema::MarkFunctionReferenced(SourceLocation Loc, 
FunctionDecl *Func,
   // Note that we skip the implicit instantiation of templates that are only
   // used in unused default arguments or by recursive calls to themselves.
   // This is formally non-conforming, but seems reasonable in practice.
-  bool NeedDefinition = !IsRecursiveCall && (OdrUse == OdrUseContext::Used ||
- NeededForConstantEvaluation);
+  bool NeedDefinition =
+  !IsRecursiveCall &&
+  (OdrUse == OdrUseContext::Used ||
+   (NeededForConstantEvaluation && !Func->isPureVirtual()));
 
   // C++14 [temp.expl.spec]p6:
   //   If a template [...] is explicitly specialized then that specialization
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 00..caec42b6b77f95
--- /dev/null
+++ b/clang/test/SemaTemplate/instantiate-pure-virtual-function.cpp
@@ -0,0 +1,67 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wundefined-func-template %s
+
+namespace GH74016 {
+  template  class B {
+  public:
+constexpr void foo(const T &) { bar(1); }
+virtual constexpr void bar(unsigned int) = 0;
+  };
+
+  template  class D : public B {
+  public:
+constexpr void bar(unsigned int) override {}
+  };
+
+  void test() {
+auto t = D();
+t.foo(0);
+  }
+};
+
+namespace call_pure_virtual_function_from_virtual {
+  template  class B {
+  public:
+const void foo(const T &) { B::bar(1); } // expected-warning 
{{instantiation of function 
'call_pure_virtual_function_from_virtual::B::bar' required here, but no 
definition is available}}
+// expected-note@-1 {{add an explicit instantiation declaration to 
suppress this warning if 'call_pure_virtual_function_from_virtual::B::bar' 
is explicitly instantiated in another translation unit}}
+virtual const void bar(unsigned int) = 0; // expected-note {{forward 
declaration of template entity is here}}
+  };
+
+  template  class D : public B {
+  public:
+const void bar(unsigned int) override {}
+  };
+
+  void test() {
+auto t = D();
+t.foo(0); // expected-note {{in instantiation of member function 
'call_pure_virtual_function_from_virtual::B::foo' requested here}}
+  }
+};
+
+namespace non_pure_virtual_function {
+  template  class B {
+  public:
+constexpr void foo(const T &) { bar(1); }
+
+virtual constexpr void bar(unsigned int); // expected-warning {{inline 
function 'non_pure_virtual_function::B::bar' is not defined}}
+// expected-note@-1 {{forward declaration of template entity is here}}
+// expected-note@-2 {{forward declaration of template entity is here}}
+// expected-note@-3 {{forward declaration of template entity is here}}
+  };
+
+  template  class D : public B { // expected-warning 
{{instantiation of function 'non_pure_virtual_function::B::bar' required 
here, but no definition is available}}
+// expected-warning@-1 {{instantiation of function 
'non_pure_virtual_function::B::bar' required here, but no definition is 
available}}
+// expected-warning@-2 {{instantiation of function 
'non_pure_virtual_function::B::bar' required here, but no definition is 
available}}
+// expected-note@-3 {{add an explicit instantiation 

[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2024-04-05 Thread Charalampos Mitrodimas via cfe-commits


@@ -18931,7 +18931,7 @@ void Sema::MarkFunctionReferenced(SourceLocation Loc, 
FunctionDecl *Func,
   //   constant evaluated
   bool NeededForConstantEvaluation =
   isPotentiallyConstantEvaluatedContext(*this) &&
-  isImplicitlyDefinableConstexprFunction(Func);
+  isImplicitlyDefinableConstexprFunction(Func) && !Func->isPure();

charmitro wrote:

You're actually right. 

I don't really recall what I was entering back when I was developing it, but it 
should work now.

https://github.com/llvm/llvm-project/pull/74510
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2024-04-05 Thread Charalampos Mitrodimas via cfe-commits

https://github.com/charmitro updated 
https://github.com/llvm/llvm-project/pull/74510

>From c0ef5a06026d449aadfadca9948d148b25d1 Mon Sep 17 00:00:00 2001
From: Charalampos Mitrodimas 
Date: Tue, 5 Dec 2023 11:46:56 +0200
Subject: [PATCH] [clang] Disable missing definition warning on pure virtual
 functions

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

Signed-off-by: Charalampos Mitrodimas 
---
 clang/docs/ReleaseNotes.rst   |  4 ++
 clang/lib/Sema/SemaExpr.cpp   |  8 ++-
 .../instantiate-pure-virtual-function.cpp | 67 +++
 3 files changed, 76 insertions(+), 3 deletions(-)
 create mode 100644 
clang/test/SemaTemplate/instantiate-pure-virtual-function.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 28e8ddb3c41c3e..15738b3fa03739 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -346,6 +346,10 @@ Improvements to Clang's time-trace
 
 Bug Fixes in This Version
 -
+- Clang's ``-Wundefined-func-template`` no longer warns on pure virtual
+  functions.
+  (`#74016 `_)
+
 - Fixed missing warnings when comparing mismatched enumeration constants
   in C (`#29217 `).
 
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 6b2eb245d58263..932c2c5a123a8d 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -18980,10 +18980,12 @@ void Sema::MarkFunctionReferenced(SourceLocation Loc, 
FunctionDecl *Func,
   // Note that we skip the implicit instantiation of templates that are only
   // used in unused default arguments or by recursive calls to themselves.
   // This is formally non-conforming, but seems reasonable in practice.
-  bool NeedDefinition = !IsRecursiveCall && (OdrUse == OdrUseContext::Used ||
- NeededForConstantEvaluation);
+  bool NeedDefinition =
+  !IsRecursiveCall &&
+  (OdrUse == OdrUseContext::Used ||
+   (NeededForConstantEvaluation && !Func->isPureVirtual()));
 
-  // C++14 [temp.expl.spec]p6:
+  // C++14 [temp.expl.spec]p6:a
   //   If a template [...] is explicitly specialized then that specialization
   //   shall be declared before the first use of that specialization that would
   //   cause an implicit instantiation to take place, in every translation unit
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 00..caec42b6b77f95
--- /dev/null
+++ b/clang/test/SemaTemplate/instantiate-pure-virtual-function.cpp
@@ -0,0 +1,67 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wundefined-func-template %s
+
+namespace GH74016 {
+  template  class B {
+  public:
+constexpr void foo(const T &) { bar(1); }
+virtual constexpr void bar(unsigned int) = 0;
+  };
+
+  template  class D : public B {
+  public:
+constexpr void bar(unsigned int) override {}
+  };
+
+  void test() {
+auto t = D();
+t.foo(0);
+  }
+};
+
+namespace call_pure_virtual_function_from_virtual {
+  template  class B {
+  public:
+const void foo(const T &) { B::bar(1); } // expected-warning 
{{instantiation of function 
'call_pure_virtual_function_from_virtual::B::bar' required here, but no 
definition is available}}
+// expected-note@-1 {{add an explicit instantiation declaration to 
suppress this warning if 'call_pure_virtual_function_from_virtual::B::bar' 
is explicitly instantiated in another translation unit}}
+virtual const void bar(unsigned int) = 0; // expected-note {{forward 
declaration of template entity is here}}
+  };
+
+  template  class D : public B {
+  public:
+const void bar(unsigned int) override {}
+  };
+
+  void test() {
+auto t = D();
+t.foo(0); // expected-note {{in instantiation of member function 
'call_pure_virtual_function_from_virtual::B::foo' requested here}}
+  }
+};
+
+namespace non_pure_virtual_function {
+  template  class B {
+  public:
+constexpr void foo(const T &) { bar(1); }
+
+virtual constexpr void bar(unsigned int); // expected-warning {{inline 
function 'non_pure_virtual_function::B::bar' is not defined}}
+// expected-note@-1 {{forward declaration of template entity is here}}
+// expected-note@-2 {{forward declaration of template entity is here}}
+// expected-note@-3 {{forward declaration of template entity is here}}
+  };
+
+  template  class D : public B { // expected-warning 
{{instantiation of function 'non_pure_virtual_function::B::bar' required 
here, but no definition is available}}
+// expected-warning@-1 {{instantiation of function 
'non_pure_virtual_function::B::bar' required here, but no definition is 

[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2024-04-05 Thread Charalampos Mitrodimas via cfe-commits

https://github.com/charmitro updated 
https://github.com/llvm/llvm-project/pull/74510

>From ffc6db2006ed503369ce79a6507fa237649e6af1 Mon Sep 17 00:00:00 2001
From: Charalampos Mitrodimas 
Date: Tue, 5 Dec 2023 11:46:56 +0200
Subject: [PATCH] [clang] Disable missing definition warning on pure virtual
 functions

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

Signed-off-by: Charalampos Mitrodimas 
---
 clang/docs/ReleaseNotes.rst   |  4 ++
 clang/lib/Sema/SemaExpr.cpp   |  5 +-
 .../instantiate-pure-virtual-function.cpp | 68 +++
 3 files changed, 75 insertions(+), 2 deletions(-)
 create mode 100644 
clang/test/SemaTemplate/instantiate-pure-virtual-function.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8054d90fc70f93..643eb6cc157732 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -294,6 +294,10 @@ Improvements to Clang's time-trace
 
 Bug Fixes in This Version
 -
+- Clang's ``-Wundefined-func-template`` no longer warns on pure virtual
+  functions.
+  (`#74016 `_)
+
 - Fixed missing warnings when comparing mismatched enumeration constants
   in C (`#29217 `).
 
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 5f03b981428251..d74dc66b1b5075 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -18975,8 +18975,9 @@ void Sema::MarkFunctionReferenced(SourceLocation Loc, 
FunctionDecl *Func,
   // Note that we skip the implicit instantiation of templates that are only
   // used in unused default arguments or by recursive calls to themselves.
   // This is formally non-conforming, but seems reasonable in practice.
-  bool NeedDefinition = !IsRecursiveCall && (OdrUse == OdrUseContext::Used ||
- NeededForConstantEvaluation);
+  bool NeedDefinition = !IsRecursiveCall &&
+(OdrUse == OdrUseContext::Used ||
+ NeededForConstantEvaluation || Func->isPureVirtual());
 
   // C++14 [temp.expl.spec]p6:
   //   If a template [...] is explicitly specialized then that specialization
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 00..1dd668a385ec84
--- /dev/null
+++ b/clang/test/SemaTemplate/instantiate-pure-virtual-function.cpp
@@ -0,0 +1,68 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wundefined-func-template %s
+
+namespace GH74016 {
+  template  class B {
+  public:
+constexpr void foo(const T &) { bar(1); } // expected-warning 
{{instantiation of function 'GH74016::B::bar' required here, but no 
definition is available}}
+// expected-note@-1 {{add an explicit instantiation declaration to 
suppress this warning if 'GH74016::B::bar' is explicitly instantiated in 
another translation unit}}
+virtual constexpr void bar(unsigned int) = 0; // expected-note {{forward 
declaration of template entity is here}}
+  };
+
+  template  class D : public B {
+  public:
+constexpr void bar(unsigned int) override {}
+  };
+
+  void test() {
+auto t = D();
+t.foo(0);
+  }
+};
+
+namespace call_pure_virtual_function_from_virtual {
+  template  class B {
+  public:
+const void foo(const T &) { B::bar(1); } // expected-warning 
{{instantiation of function 
'call_pure_virtual_function_from_virtual::B::bar' required here, but no 
definition is available}}
+// expected-note@-1 {{add an explicit instantiation declaration to 
suppress this warning if 'call_pure_virtual_function_from_virtual::B::bar' 
is explicitly instantiated in another translation unit}}
+virtual const void bar(unsigned int) = 0; // expected-note {{forward 
declaration of template entity is here}}
+  };
+
+  template  class D : public B {
+  public:
+const void bar(unsigned int) override {}
+  };
+
+  void test() {
+auto t = D();
+t.foo(0); // expected-note {{in instantiation of member function 
'call_pure_virtual_function_from_virtual::B::foo' requested here}}
+  }
+};
+
+namespace non_pure_virtual_function {
+  template  class B {
+  public:
+constexpr void foo(const T &) { bar(1); }
+
+virtual constexpr void bar(unsigned int); // expected-warning {{inline 
function 'non_pure_virtual_function::B::bar' is not defined}}
+// expected-note@-1 {{forward declaration of template entity is here}}
+// expected-note@-2 {{forward declaration of template entity is here}}
+// expected-note@-3 {{forward declaration of template entity is here}}
+  };
+
+  template  class D : public B { // expected-warning 
{{instantiation of function 

[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2024-04-04 Thread Shafik Yaghmour via cfe-commits


@@ -18931,7 +18931,7 @@ void Sema::MarkFunctionReferenced(SourceLocation Loc, 
FunctionDecl *Func,
   //   constant evaluated
   bool NeededForConstantEvaluation =
   isPotentiallyConstantEvaluatedContext(*this) &&
-  isImplicitlyDefinableConstexprFunction(Func);
+  isImplicitlyDefinableConstexprFunction(Func) && !Func->isPure();

shafik wrote:

I am not sure why moving it down silences the diagnostic, I would think doing 
`(OdrUse == OdrUseContext::Used || NeededForConstantEvaluation || 
!Func->isPure())` should work. 

Can you explain in more detail?

https://github.com/llvm/llvm-project/pull/74510
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2024-04-04 Thread Shafik Yaghmour via cfe-commits


@@ -18931,7 +18931,7 @@ void Sema::MarkFunctionReferenced(SourceLocation Loc, 
FunctionDecl *Func,
   //   constant evaluated
   bool NeededForConstantEvaluation =
   isPotentiallyConstantEvaluatedContext(*this) &&
-  isImplicitlyDefinableConstexprFunction(Func);
+  isImplicitlyDefinableConstexprFunction(Func) && !Func->isPure();

shafik wrote:

Thank to @erichkeane I realized I am wrong, we can actually define a pure 
virtual function. So we do want to retain the diagnostic here.

https://github.com/llvm/llvm-project/pull/74510
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2024-04-04 Thread Shafik Yaghmour via cfe-commits


@@ -18931,7 +18931,7 @@ void Sema::MarkFunctionReferenced(SourceLocation Loc, 
FunctionDecl *Func,
   //   constant evaluated
   bool NeededForConstantEvaluation =
   isPotentiallyConstantEvaluatedContext(*this) &&
-  isImplicitlyDefinableConstexprFunction(Func);
+  isImplicitlyDefinableConstexprFunction(Func) && !Func->isPure();

shafik wrote:

I am not sure the diagnostic makes sense in that case since it can never 
actually be called. 

https://github.com/llvm/llvm-project/pull/74510
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2024-03-23 Thread Charalampos Mitrodimas via cfe-commits

https://github.com/charmitro updated 
https://github.com/llvm/llvm-project/pull/74510

>From 89eb978ece40cd99b3ac535ae25191e0edadb378 Mon Sep 17 00:00:00 2001
From: Charalampos Mitrodimas 
Date: Tue, 5 Dec 2023 11:46:56 +0200
Subject: [PATCH] [clang] Disable missing definition warning on pure virtual
 functions

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

Signed-off-by: Charalampos Mitrodimas 
---
 clang/docs/ReleaseNotes.rst   |  4 ++
 clang/lib/Sema/SemaExpr.cpp   |  2 +-
 .../instantiate-pure-virtual-function.cpp | 67 +++
 3 files changed, 72 insertions(+), 1 deletion(-)
 create mode 100644 
clang/test/SemaTemplate/instantiate-pure-virtual-function.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8054d90fc70f93..643eb6cc157732 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -294,6 +294,10 @@ Improvements to Clang's time-trace
 
 Bug Fixes in This Version
 -
+- Clang's ``-Wundefined-func-template`` no longer warns on pure virtual
+  functions.
+  (`#74016 `_)
+
 - Fixed missing warnings when comparing mismatched enumeration constants
   in C (`#29217 `).
 
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 5f03b981428251..c696f5eee31dec 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -18952,7 +18952,7 @@ void Sema::MarkFunctionReferenced(SourceLocation Loc, 
FunctionDecl *Func,
   //   constant evaluated
   bool NeededForConstantEvaluation =
   isPotentiallyConstantEvaluatedContext(*this) &&
-  isImplicitlyDefinableConstexprFunction(Func);
+  isImplicitlyDefinableConstexprFunction(Func) && !Func->isPureVirtual();
 
   // Determine whether we require a function definition to exist, per
   // C++11 [temp.inst]p3:
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 00..caec42b6b77f95
--- /dev/null
+++ b/clang/test/SemaTemplate/instantiate-pure-virtual-function.cpp
@@ -0,0 +1,67 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wundefined-func-template %s
+
+namespace GH74016 {
+  template  class B {
+  public:
+constexpr void foo(const T &) { bar(1); }
+virtual constexpr void bar(unsigned int) = 0;
+  };
+
+  template  class D : public B {
+  public:
+constexpr void bar(unsigned int) override {}
+  };
+
+  void test() {
+auto t = D();
+t.foo(0);
+  }
+};
+
+namespace call_pure_virtual_function_from_virtual {
+  template  class B {
+  public:
+const void foo(const T &) { B::bar(1); } // expected-warning 
{{instantiation of function 
'call_pure_virtual_function_from_virtual::B::bar' required here, but no 
definition is available}}
+// expected-note@-1 {{add an explicit instantiation declaration to 
suppress this warning if 'call_pure_virtual_function_from_virtual::B::bar' 
is explicitly instantiated in another translation unit}}
+virtual const void bar(unsigned int) = 0; // expected-note {{forward 
declaration of template entity is here}}
+  };
+
+  template  class D : public B {
+  public:
+const void bar(unsigned int) override {}
+  };
+
+  void test() {
+auto t = D();
+t.foo(0); // expected-note {{in instantiation of member function 
'call_pure_virtual_function_from_virtual::B::foo' requested here}}
+  }
+};
+
+namespace non_pure_virtual_function {
+  template  class B {
+  public:
+constexpr void foo(const T &) { bar(1); }
+
+virtual constexpr void bar(unsigned int); // expected-warning {{inline 
function 'non_pure_virtual_function::B::bar' is not defined}}
+// expected-note@-1 {{forward declaration of template entity is here}}
+// expected-note@-2 {{forward declaration of template entity is here}}
+// expected-note@-3 {{forward declaration of template entity is here}}
+  };
+
+  template  class D : public B { // expected-warning 
{{instantiation of function 'non_pure_virtual_function::B::bar' required 
here, but no definition is available}}
+// expected-warning@-1 {{instantiation of function 
'non_pure_virtual_function::B::bar' required here, but no definition is 
available}}
+// expected-warning@-2 {{instantiation of function 
'non_pure_virtual_function::B::bar' required here, but no definition is 
available}}
+// expected-note@-3 {{add an explicit instantiation declaration to suppress 
this warning if 'non_pure_virtual_function::B::bar' is explicitly 
instantiated in another translation unit}}
+// expected-note@-4 {{add an explicit instantiation declaration to suppress 
this warning if 'non_pure_virtual_function::B::bar' is explicitly 
instantiated in another 

[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2024-03-23 Thread via cfe-commits

github-actions[bot] wrote:



:white_check_mark: With the latest revision this PR passed the Python code 
formatter.

https://github.com/llvm/llvm-project/pull/74510
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2024-03-23 Thread Charalampos Mitrodimas via cfe-commits

https://github.com/charmitro updated 
https://github.com/llvm/llvm-project/pull/74510

>From 7961a90a020f6fde5c6cd892024ff0fe329450ee Mon Sep 17 00:00:00 2001
From: Charalampos Mitrodimas 
Date: Tue, 5 Dec 2023 11:46:56 +0200
Subject: [PATCH] [clang] Disable missing definition warning on pure virtual
 functions

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

Signed-off-by: Charalampos Mitrodimas 
---
 clang/docs/ReleaseNotes.rst   |  4 ++
 clang/lib/Sema/SemaExpr.cpp   |  2 +-
 .../instantiate-pure-virtual-function.cpp | 67 +++
 3 files changed, 72 insertions(+), 1 deletion(-)
 create mode 100644 
clang/test/SemaTemplate/instantiate-pure-virtual-function.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8054d90fc70f93..643eb6cc157732 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -294,6 +294,10 @@ Improvements to Clang's time-trace
 
 Bug Fixes in This Version
 -
+- Clang's ``-Wundefined-func-template`` no longer warns on pure virtual
+  functions.
+  (`#74016 `_)
+
 - Fixed missing warnings when comparing mismatched enumeration constants
   in C (`#29217 `).
 
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 5f03b981428251..7eb252f663d43e 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -18952,7 +18952,7 @@ void Sema::MarkFunctionReferenced(SourceLocation Loc, 
FunctionDecl *Func,
   //   constant evaluated
   bool NeededForConstantEvaluation =
   isPotentiallyConstantEvaluatedContext(*this) &&
-  isImplicitlyDefinableConstexprFunction(Func);
+  isImplicitlyDefinableConstexprFunction(Func) && !Func->isPure();
 
   // Determine whether we require a function definition to exist, per
   // C++11 [temp.inst]p3:
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 00..caec42b6b77f95
--- /dev/null
+++ b/clang/test/SemaTemplate/instantiate-pure-virtual-function.cpp
@@ -0,0 +1,67 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wundefined-func-template %s
+
+namespace GH74016 {
+  template  class B {
+  public:
+constexpr void foo(const T &) { bar(1); }
+virtual constexpr void bar(unsigned int) = 0;
+  };
+
+  template  class D : public B {
+  public:
+constexpr void bar(unsigned int) override {}
+  };
+
+  void test() {
+auto t = D();
+t.foo(0);
+  }
+};
+
+namespace call_pure_virtual_function_from_virtual {
+  template  class B {
+  public:
+const void foo(const T &) { B::bar(1); } // expected-warning 
{{instantiation of function 
'call_pure_virtual_function_from_virtual::B::bar' required here, but no 
definition is available}}
+// expected-note@-1 {{add an explicit instantiation declaration to 
suppress this warning if 'call_pure_virtual_function_from_virtual::B::bar' 
is explicitly instantiated in another translation unit}}
+virtual const void bar(unsigned int) = 0; // expected-note {{forward 
declaration of template entity is here}}
+  };
+
+  template  class D : public B {
+  public:
+const void bar(unsigned int) override {}
+  };
+
+  void test() {
+auto t = D();
+t.foo(0); // expected-note {{in instantiation of member function 
'call_pure_virtual_function_from_virtual::B::foo' requested here}}
+  }
+};
+
+namespace non_pure_virtual_function {
+  template  class B {
+  public:
+constexpr void foo(const T &) { bar(1); }
+
+virtual constexpr void bar(unsigned int); // expected-warning {{inline 
function 'non_pure_virtual_function::B::bar' is not defined}}
+// expected-note@-1 {{forward declaration of template entity is here}}
+// expected-note@-2 {{forward declaration of template entity is here}}
+// expected-note@-3 {{forward declaration of template entity is here}}
+  };
+
+  template  class D : public B { // expected-warning 
{{instantiation of function 'non_pure_virtual_function::B::bar' required 
here, but no definition is available}}
+// expected-warning@-1 {{instantiation of function 
'non_pure_virtual_function::B::bar' required here, but no definition is 
available}}
+// expected-warning@-2 {{instantiation of function 
'non_pure_virtual_function::B::bar' required here, but no definition is 
available}}
+// expected-note@-3 {{add an explicit instantiation declaration to suppress 
this warning if 'non_pure_virtual_function::B::bar' is explicitly 
instantiated in another translation unit}}
+// expected-note@-4 {{add an explicit instantiation declaration to suppress 
this warning if 'non_pure_virtual_function::B::bar' is explicitly 
instantiated in another 

[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2024-01-11 Thread Charalampos Mitrodimas via cfe-commits


@@ -18931,7 +18931,7 @@ void Sema::MarkFunctionReferenced(SourceLocation Loc, 
FunctionDecl *Func,
   //   constant evaluated
   bool NeededForConstantEvaluation =
   isPotentiallyConstantEvaluatedContext(*this) &&
-  isImplicitlyDefinableConstexprFunction(Func);
+  isImplicitlyDefinableConstexprFunction(Func) && !Func->isPure();

charmitro wrote:

Moving it to `NeedDefinition` silences the warnings of test 
`call_pure_virtual_function_from_virtual`, where we still require warnings for 
it, as mentioned in 
https://github.com/llvm/llvm-project/issues/74016#issuecomment-1845636487.

https://github.com/llvm/llvm-project/pull/74510
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2024-01-11 Thread Shafik Yaghmour via cfe-commits


@@ -18931,7 +18931,7 @@ void Sema::MarkFunctionReferenced(SourceLocation Loc, 
FunctionDecl *Func,
   //   constant evaluated
   bool NeededForConstantEvaluation =
   isPotentiallyConstantEvaluatedContext(*this) &&
-  isImplicitlyDefinableConstexprFunction(Func);
+  isImplicitlyDefinableConstexprFunction(Func) && !Func->isPure();

shafik wrote:

I concur, this does not make sense doing the check here.

https://github.com/llvm/llvm-project/pull/74510
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2024-01-11 Thread Aaron Ballman via cfe-commits


@@ -18931,7 +18931,7 @@ void Sema::MarkFunctionReferenced(SourceLocation Loc, 
FunctionDecl *Func,
   //   constant evaluated
   bool NeededForConstantEvaluation =
   isPotentiallyConstantEvaluatedContext(*this) &&
-  isImplicitlyDefinableConstexprFunction(Func);
+  isImplicitlyDefinableConstexprFunction(Func) && !Func->isPure();

AaronBallman wrote:

I don't understand how the function being pure relates to whether it's needed 
for constant evaluation. I think this should move down to `NeedDefinition` 
below?

https://github.com/llvm/llvm-project/pull/74510
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2024-01-11 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman approved this pull request.

Aside from a minor NFC nit with where we decide to do the check, this LGTM

https://github.com/llvm/llvm-project/pull/74510
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2024-01-11 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman edited 
https://github.com/llvm/llvm-project/pull/74510
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2024-01-05 Thread Charalampos Mitrodimas via cfe-commits

https://github.com/charmitro updated 
https://github.com/llvm/llvm-project/pull/74510

>From f60f12f8e4e8b70a8fdf2aa9398b94849a863fff Mon Sep 17 00:00:00 2001
From: Charalampos Mitrodimas 
Date: Tue, 5 Dec 2023 11:46:56 +0200
Subject: [PATCH] [clang] Disable missing definition warning on pure virtual
 functions

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

Signed-off-by: Charalampos Mitrodimas 
---
 clang/docs/ReleaseNotes.rst   |  3 +
 clang/lib/Sema/SemaExpr.cpp   |  2 +-
 .../instantiate-pure-virtual-function.cpp | 67 +++
 3 files changed, 71 insertions(+), 1 deletion(-)
 create mode 100644 
clang/test/SemaTemplate/instantiate-pure-virtual-function.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ce7599ad34beaf..858248f3cce896 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -531,6 +531,9 @@ Improvements to Clang's time-trace
 
 Bug Fixes in This Version
 -
+- Clang's ``-Wundefined-func-template`` no longer warns on pure virtual
+  functions.
+  (`#74016 `_)
 - Fixed an issue where a class template specialization whose declaration is
   instantiated in one module and whose definition is instantiated in another
   module may end up with members associated with the wrong declaration of the
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 960f513db2..43b266ec07dd35 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -18931,7 +18931,7 @@ void Sema::MarkFunctionReferenced(SourceLocation Loc, 
FunctionDecl *Func,
   //   constant evaluated
   bool NeededForConstantEvaluation =
   isPotentiallyConstantEvaluatedContext(*this) &&
-  isImplicitlyDefinableConstexprFunction(Func);
+  isImplicitlyDefinableConstexprFunction(Func) && !Func->isPure();
 
   // Determine whether we require a function definition to exist, per
   // C++11 [temp.inst]p3:
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 00..caec42b6b77f95
--- /dev/null
+++ b/clang/test/SemaTemplate/instantiate-pure-virtual-function.cpp
@@ -0,0 +1,67 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wundefined-func-template %s
+
+namespace GH74016 {
+  template  class B {
+  public:
+constexpr void foo(const T &) { bar(1); }
+virtual constexpr void bar(unsigned int) = 0;
+  };
+
+  template  class D : public B {
+  public:
+constexpr void bar(unsigned int) override {}
+  };
+
+  void test() {
+auto t = D();
+t.foo(0);
+  }
+};
+
+namespace call_pure_virtual_function_from_virtual {
+  template  class B {
+  public:
+const void foo(const T &) { B::bar(1); } // expected-warning 
{{instantiation of function 
'call_pure_virtual_function_from_virtual::B::bar' required here, but no 
definition is available}}
+// expected-note@-1 {{add an explicit instantiation declaration to 
suppress this warning if 'call_pure_virtual_function_from_virtual::B::bar' 
is explicitly instantiated in another translation unit}}
+virtual const void bar(unsigned int) = 0; // expected-note {{forward 
declaration of template entity is here}}
+  };
+
+  template  class D : public B {
+  public:
+const void bar(unsigned int) override {}
+  };
+
+  void test() {
+auto t = D();
+t.foo(0); // expected-note {{in instantiation of member function 
'call_pure_virtual_function_from_virtual::B::foo' requested here}}
+  }
+};
+
+namespace non_pure_virtual_function {
+  template  class B {
+  public:
+constexpr void foo(const T &) { bar(1); }
+
+virtual constexpr void bar(unsigned int); // expected-warning {{inline 
function 'non_pure_virtual_function::B::bar' is not defined}}
+// expected-note@-1 {{forward declaration of template entity is here}}
+// expected-note@-2 {{forward declaration of template entity is here}}
+// expected-note@-3 {{forward declaration of template entity is here}}
+  };
+
+  template  class D : public B { // expected-warning 
{{instantiation of function 'non_pure_virtual_function::B::bar' required 
here, but no definition is available}}
+// expected-warning@-1 {{instantiation of function 
'non_pure_virtual_function::B::bar' required here, but no definition is 
available}}
+// expected-warning@-2 {{instantiation of function 
'non_pure_virtual_function::B::bar' required here, but no definition is 
available}}
+// expected-note@-3 {{add an explicit instantiation declaration to suppress 
this warning if 'non_pure_virtual_function::B::bar' is explicitly 
instantiated in another translation unit}}
+// expected-note@-4 {{add an explicit instantiation declaration to suppress 
this warning if 

[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2024-01-04 Thread Akira Hatanaka via cfe-commits

ahatanak wrote:

Any progress on this patch?

As we discussed in https://github.com/llvm/llvm-project/issues/74016, we should 
make sure clang doesn't stop emitting the warning when the definition of a pure 
virtual function is actually needed.

It seems to me that we shouldn't set `NeededForConstantEvaluation` or 
`NeedDefinition` in `Sema::MarkFunctionReferenced` to true when a pure virtual 
function is used in a virtual function call.

https://github.com/llvm/llvm-project/pull/74510
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2023-12-06 Thread via cfe-commits

https://github.com/cor3ntin approved this pull request.

LGTM, thanks

https://github.com/llvm/llvm-project/pull/74510
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2023-12-06 Thread Charalampos Mitrodimas via cfe-commits

charmitro wrote:

> Perhaps needs a release note.

> Can you add a release note indicating #74016 was fixed? Otherwise LGTM.

Release note added.

> If you wanted to make a follow up {R to rename `isPure` to `isPureVirtual`, i 
> think that might be helpful (to avoid confusion with the `gnu::pure` 
> attribute)

Yes, this could be helpful. I'll create a follow up PR for this.


https://github.com/llvm/llvm-project/pull/74510
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2023-12-06 Thread Charalampos Mitrodimas via cfe-commits

https://github.com/charmitro updated 
https://github.com/llvm/llvm-project/pull/74510

>From 83d29e896b7ae0b5b259cbf179143e526dc37b1c Mon Sep 17 00:00:00 2001
From: Charalampos Mitrodimas 
Date: Tue, 5 Dec 2023 11:46:56 +0200
Subject: [PATCH] [clang] Disable missing definition warning on pure virtual
 functions

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

Signed-off-by: Charalampos Mitrodimas 
---
 clang/docs/ReleaseNotes.rst   |  3 ++
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  3 +-
 .../instantiate-pure-virtual-function.cpp | 48 +++
 3 files changed, 53 insertions(+), 1 deletion(-)
 create mode 100644 
clang/test/SemaTemplate/instantiate-pure-virtual-function.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 828dd10e3d6db..10dce199b9fd1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -514,6 +514,9 @@ Improvements to Clang's time-trace
 
 Bug Fixes in This Version
 -
+- Clang's ``-Wundefined-func-template`` no longer warns on pure virtual
+  functions.
+  (`#74016 `_)
 - Fixed an issue where a class template specialization whose declaration is
   instantiated in one module and whose definition is instantiated in another
   module may end up with members associated with the wrong declaration of the
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index d768bb72e07c0..a034de0697b2b 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->isPure()) {
 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 0..d188adc9ed034
--- /dev/null
+++ b/clang/test/SemaTemplate/instantiate-pure-virtual-function.cpp
@@ -0,0 +1,48 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wundefined-func-template %s
+
+namespace GH74016 {
+  template  class B {
+  public:
+constexpr void foo(const T &) { bar(1); }
+virtual constexpr void bar(unsigned int) = 0;
+  };
+
+  template  class D : public B {
+  public:
+constexpr void bar(unsigned int) override {}
+  };
+
+  void test() {
+auto t = D();
+t.foo(0);
+  }
+};
+
+namespace non_pure_virtual_function {
+  template  class B {
+  public:
+constexpr void foo(const T &) { bar(1); }
+
+virtual constexpr void bar(unsigned int); // expected-warning {{inline 
function 'non_pure_virtual_function::B::bar' is not defined}}
+// expected-note@-1 {{forward declaration of template entity is here}}
+// expected-note@-2 {{forward declaration of template entity is here}}
+// expected-note@-3 {{forward declaration of template entity is here}}
+  };
+
+  template  class D : public B { // expected-warning 
{{instantiation of function 'non_pure_virtual_function::B::bar' required 
here, but no definition is available}}
+// expected-warning@-1 {{instantiation of function 
'non_pure_virtual_function::B::bar' required here, but no definition is 
available}}
+// expected-warning@-2 {{instantiation of function 
'non_pure_virtual_function::B::bar' required here, but no definition is 
available}}
+// expected-note@-3 {{add an explicit instantiation declaration to suppress 
this warning if 'non_pure_virtual_function::B::bar' is explicitly 
instantiated in another translation unit}}
+// expected-note@-4 {{add an explicit instantiation declaration to suppress 
this warning if 'non_pure_virtual_function::B::bar' is explicitly 
instantiated in another translation unit}}
+// expected-note@-5 {{add an explicit instantiation declaration to suppress 
this warning if 'non_pure_virtual_function::B::bar' is explicitly 
instantiated in another translation unit}}
+// expected-note@-6 {{used here}}
+
+  public:
+constexpr void bar(unsigned int) override { }
+  };
+
+  void test() {
+auto t = D();
+t.foo(0);
+  }
+};

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2023-12-05 Thread via cfe-commits

cor3ntin wrote:

Can you add a release note indicating 
https://github.com/llvm/llvm-project/issues/74016 was fixed?
Otherwise LGTM.

If you wanted to make a follow up {R to rename `isPure` to `isPureVirtual`, i 
think that might be helpful (to avoid confusion with the `gnu::pure` attribute)

https://github.com/llvm/llvm-project/pull/74510
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2023-12-05 Thread Charalampos Mitrodimas via cfe-commits

https://github.com/charmitro updated 
https://github.com/llvm/llvm-project/pull/74510

>From 5582cfacf106a7c00912fcef0d116d6fa58e064b Mon Sep 17 00:00:00 2001
From: Charalampos Mitrodimas 
Date: Tue, 5 Dec 2023 11:46:56 +0200
Subject: [PATCH] [clang] Disable missing definition warning on pure virtual
 functions

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

Signed-off-by: Charalampos Mitrodimas 
---
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  3 +-
 .../instantiate-pure-virtual-function.cpp | 48 +++
 2 files changed, 50 insertions(+), 1 deletion(-)
 create mode 100644 
clang/test/SemaTemplate/instantiate-pure-virtual-function.cpp

diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index d768bb72e07c0..a034de0697b2b 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->isPure()) {
 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 0..09164e8a79f96
--- /dev/null
+++ b/clang/test/SemaTemplate/instantiate-pure-virtual-function.cpp
@@ -0,0 +1,48 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wundefined-func-template %s
+
+namespace GH74016 {
+  template  class B {
+  public:
+constexpr void foo(const T &) { bar(1); }
+virtual constexpr void bar(unsigned int) = 0;
+  };
+
+  template  class D : public B {
+  public:
+constexpr void bar(unsigned int) override {}
+  };
+
+  void test() {
+auto t = D();
+t.foo(0);
+  }
+};
+
+namespace non_pure_virtual_function {
+  template  class B {
+  public:
+constexpr void foo(const T &) { bar(1); }
+
+virtual constexpr void bar(unsigned int); // expected-warning {{inline 
function 'non_pure_virtual_function::B::bar' is not defined}}
+// expected-note@-1 {{forward declaration of template entity is here}}
+// expected-note@-2 {{forward declaration of template entity is here}}
+// expected-note@-3 {{forward declaration of template entity is here}}
+  };
+
+  template  class D : public B { // expected-warning 
{{instantiation of function 'non_pure_virtual_function::B::bar' required 
here, but no definition is available}}
+// expected-warning@-1 {{instantiation of function 
'non_pure_virtual_function::B::bar' required here, but no definition is 
available}}
+// expected-warning@-2 {{instantiation of function 
'non_pure_virtual_function::B::bar' required here, but no definition is 
available}}
+// expected-note@-3 {{add an explicit instantiation declaration to suppress 
this warning if 'non_pure_virtual_function::B::bar' is explicitly 
instantiated in another translation unit}}
+// expected-note@-4 {{add an explicit instantiation declaration to suppress 
this warning if 'non_pure_virtual_function::B::bar' is explicitly 
instantiated in another translation unit}}
+// expected-note@-5 {{add an explicit instantiation declaration to suppress 
this warning if 'non_pure_virtual_function::B::bar' is explicitly 
instantiated in another translation unit}}
+// expected-note@-6 {{used here}}
+
+  public:
+constexpr void bar(unsigned int) override { }
+  };
+
+  void test() {
+auto t = D();
+t.foo(0);
+  }
+};

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2023-12-05 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff d6fbd96e5eaf3e8acbf1b43dce7a311352907567 
1140e0094137614ad9917276f5324cbea4f2e0f9 -- 
clang/test/SemaTemplate/instantiate-pure-virtual-function.cpp 
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 5611bb6f5b..a034de0697 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4953,7 +4953,7 @@ void Sema::InstantiateFunctionDefinition(SourceLocation 
PointOfInstantiation,
 } else if (TSK == TSK_ImplicitInstantiation) {
   if (AtEndOfTU && !getDiagnostics().hasErrorOccurred() &&
   !getSourceManager().isInSystemHeader(PatternDecl->getBeginLoc()) &&
-   !Function->isPure()) {
+  !Function->isPure()) {
 Diag(PointOfInstantiation, diag::warn_func_template_missing)
   << Function;
 Diag(PatternDecl->getLocation(), diag::note_forward_template_decl);

``




https://github.com/llvm/llvm-project/pull/74510
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2023-12-05 Thread Charalampos Mitrodimas via cfe-commits

https://github.com/charmitro edited 
https://github.com/llvm/llvm-project/pull/74510
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2023-12-05 Thread Charalampos Mitrodimas via cfe-commits


@@ -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() && !Function->isPure()) {

charmitro wrote:

After double-checking this, I think we should just check for `isPure()` and 
don't bother checking for `isVirtualAsWritten()` at all since non-virtual 
functions cannot be pure. Also, for reference,

https://github.com/llvm/llvm-project/blob/d6fbd96e5eaf3e8acbf1b43dce7a311352907567/clang/include/clang/AST/Decl.h#L2293-L2295

Code updated to match this. Also a test-case added to verify that non-pure 
virtual functions still get diagnosed.

https://github.com/llvm/llvm-project/pull/74510
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2023-12-05 Thread Charalampos Mitrodimas via cfe-commits

https://github.com/charmitro updated 
https://github.com/llvm/llvm-project/pull/74510

>From 1140e0094137614ad9917276f5324cbea4f2e0f9 Mon Sep 17 00:00:00 2001
From: Charalampos Mitrodimas 
Date: Tue, 5 Dec 2023 11:46:56 +0200
Subject: [PATCH] [clang] Disable missing definition warning on pure virtual
 functions

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

Signed-off-by: Charalampos Mitrodimas 
---
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  3 +-
 .../instantiate-pure-virtual-function.cpp | 48 +++
 2 files changed, 50 insertions(+), 1 deletion(-)
 create mode 100644 
clang/test/SemaTemplate/instantiate-pure-virtual-function.cpp

diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index d768bb72e07c0..5611bb6f5b018 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->isPure()) {
 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 0..09164e8a79f96
--- /dev/null
+++ b/clang/test/SemaTemplate/instantiate-pure-virtual-function.cpp
@@ -0,0 +1,48 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wundefined-func-template %s
+
+namespace GH74016 {
+  template  class B {
+  public:
+constexpr void foo(const T &) { bar(1); }
+virtual constexpr void bar(unsigned int) = 0;
+  };
+
+  template  class D : public B {
+  public:
+constexpr void bar(unsigned int) override {}
+  };
+
+  void test() {
+auto t = D();
+t.foo(0);
+  }
+};
+
+namespace non_pure_virtual_function {
+  template  class B {
+  public:
+constexpr void foo(const T &) { bar(1); }
+
+virtual constexpr void bar(unsigned int); // expected-warning {{inline 
function 'non_pure_virtual_function::B::bar' is not defined}}
+// expected-note@-1 {{forward declaration of template entity is here}}
+// expected-note@-2 {{forward declaration of template entity is here}}
+// expected-note@-3 {{forward declaration of template entity is here}}
+  };
+
+  template  class D : public B { // expected-warning 
{{instantiation of function 'non_pure_virtual_function::B::bar' required 
here, but no definition is available}}
+// expected-warning@-1 {{instantiation of function 
'non_pure_virtual_function::B::bar' required here, but no definition is 
available}}
+// expected-warning@-2 {{instantiation of function 
'non_pure_virtual_function::B::bar' required here, but no definition is 
available}}
+// expected-note@-3 {{add an explicit instantiation declaration to suppress 
this warning if 'non_pure_virtual_function::B::bar' is explicitly 
instantiated in another translation unit}}
+// expected-note@-4 {{add an explicit instantiation declaration to suppress 
this warning if 'non_pure_virtual_function::B::bar' is explicitly 
instantiated in another translation unit}}
+// expected-note@-5 {{add an explicit instantiation declaration to suppress 
this warning if 'non_pure_virtual_function::B::bar' is explicitly 
instantiated in another translation unit}}
+// expected-note@-6 {{used here}}
+
+  public:
+constexpr void bar(unsigned int) override { }
+  };
+
+  void test() {
+auto t = D();
+t.foo(0);
+  }
+};

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2023-12-05 Thread via cfe-commits


@@ -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() && !Function->isPure()) {

cor3ntin wrote:

```suggestion
  !(Function->isVirtualAsWritten() && Function->isPure()) {
```

Can you add a test to make sure non-pure virtual function still get diagnosed?

https://github.com/llvm/llvm-project/pull/74510
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2023-12-05 Thread Charalampos Mitrodimas via cfe-commits


@@ -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()) {

charmitro wrote:

Updated.

https://github.com/llvm/llvm-project/pull/74510
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2023-12-05 Thread Charalampos Mitrodimas via cfe-commits


@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wundefined-func-template %s
+// expected-no-diagnostics
+
+namespace PR74016 {

charmitro wrote:

Fixed. I wasn't aware of this, thanks!

https://github.com/llvm/llvm-project/pull/74510
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2023-12-05 Thread Charalampos Mitrodimas via cfe-commits

https://github.com/charmitro updated 
https://github.com/llvm/llvm-project/pull/74510

>From 0be0d65a74cf7a6a06150362b68adff122a3a39b Mon Sep 17 00:00:00 2001
From: Charalampos Mitrodimas 
Date: Tue, 5 Dec 2023 11:46:56 +0200
Subject: [PATCH] [clang] Disable missing definition warning on pure virtual
 functions

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

Signed-off-by: Charalampos Mitrodimas 
---
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  3 ++-
 .../instantiate-pure-virtual-function.cpp | 20 +++
 2 files changed, 22 insertions(+), 1 deletion(-)
 create mode 100644 
clang/test/SemaTemplate/instantiate-pure-virtual-function.cpp

diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index d768bb72e07c0..e6704c6f80808 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() && !Function->isPure()) {
 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 0..46aaf70c7efa4
--- /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 GH74016 {
+  template  class B {
+  public:
+constexpr void foo(const T &) { bar(1); }
+virtual constexpr void bar(unsigned int) = 0;
+  };
+
+  template  class D : public B {
+  public:
+constexpr void bar(unsigned int) override {}
+  };
+
+  void test() {
+auto t = D();
+t.foo(0);
+  }
+};

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2023-12-05 Thread Mariya Podchishchaeva via cfe-commits


@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wundefined-func-template %s
+// expected-no-diagnostics
+
+namespace PR74016 {

Fznamznon wrote:

I think we normally call them GH when a bug was filed as a GitHub issue.
```suggestion
namespace GH74016 {
```

https://github.com/llvm/llvm-project/pull/74510
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2023-12-05 Thread Mariya Podchishchaeva via cfe-commits


@@ -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()) {

Fznamznon wrote:

Should we also check that it is pure? AFAIK `isVirtualAsWritten` returns true 
for function marked explicitly virtual. There is also `FunctionDecl::isPure()` 
to check that it is pure.

https://github.com/llvm/llvm-project/pull/74510
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2023-12-05 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon commented:

Perhaps needs a release note.

https://github.com/llvm/llvm-project/pull/74510
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2023-12-05 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon edited 
https://github.com/llvm/llvm-project/pull/74510
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2023-12-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Charalampos Mitrodimas (charmitro)


Changes

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 0..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  class B {
+  public:
+constexpr void foo(const T &) { bar(1); }
+virtual constexpr void bar(unsigned int) = 0;
+  };
+
+  template  class D : public B {
+  public:
+constexpr void bar(unsigned int) override {}
+  };
+
+  void test() {
+auto t = D();
+t.foo(0);
+  }
+};

``




https://github.com/llvm/llvm-project/pull/74510
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Disable missing definition warning on pure virtual functions (PR #74510)

2023-12-05 Thread Charalampos Mitrodimas via cfe-commits

https://github.com/charmitro created 
https://github.com/llvm/llvm-project/pull/74510

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

>From 0ea96c48931c99c102b6db70767ecc4c0a9bb53e Mon Sep 17 00:00:00 2001
From: Charalampos Mitrodimas 
Date: Tue, 5 Dec 2023 11:46:56 +0200
Subject: [PATCH] [clang] Disable missing definition warning on pure virtual
 functions

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

Signed-off-by: Charalampos Mitrodimas 
---
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  3 ++-
 .../instantiate-pure-virtual-function.cpp | 20 +++
 2 files changed, 22 insertions(+), 1 deletion(-)
 create mode 100644 
clang/test/SemaTemplate/instantiate-pure-virtual-function.cpp

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 0..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  class B {
+  public:
+constexpr void foo(const T &) { bar(1); }
+virtual constexpr void bar(unsigned int) = 0;
+  };
+
+  template  class D : public B {
+  public:
+constexpr void bar(unsigned int) override {}
+  };
+
+  void test() {
+auto t = D();
+t.foo(0);
+  }
+};

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits