[clang] [Clang] Add diagnostic for why std::is_abstract is false (PR #156199)

Shafik Yaghmour via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 22 17:53:30 PDT 2025


================
@@ -964,3 +964,79 @@ namespace is_aggregate {
 
   static_assert(__is_aggregate(S7[10]));
 }
+
+namespace is_abstract_tests {
+struct Abstract1 {
+  virtual void fn1() = 0;
+};
+
+struct Abstract2 {
+   virtual void fn2() = 0;
+};
+
+struct NonAbstract
+{
+   virtual void f() {}
+};
+
+// Multiple inheritance reports all abstract base classes that had their pure virtual functions overridden.
+struct Overrides : Abstract1, Abstract2, NonAbstract {
+  void fn1() override {}
+  void fn2() override {}
+};
+
+static_assert(__is_abstract(Overrides));
+// expected-error at -1 {{static assertion failed due to requirement '__is_abstract(is_abstract_tests::Overrides)'}} \
+// expected-note at -1 {{'Overrides' is not abstract}} \
+// expected-note at -1 {{because it overrides all pure virtual functions from base class 'Abstract1'}} \
+// expected-note at -1 {{because it overrides all pure virtual functions from base class 'Abstract2'}} \
+
+// Inheriting over two levels reports the last class only although the source of the pure virtual function
+// is the top-most base.
+struct Derived : Abstract1 {
+};
+
+struct Derived2 : Derived {
+   void fn1() override {}
+};
+
+static_assert(__is_abstract(Derived2));
+// expected-error at -1 {{static assertion failed due to requirement '__is_abstract(is_abstract_tests::Derived2)'}} \
+// expected-note at -1 {{'Derived2' is not abstract}} \
+// expected-note at -1 {{because it overrides all pure virtual functions from base class 'Derived'}} \
+
+
+using I = int;
+static_assert(__is_abstract(I));
+// expected-error at -1 {{static assertion failed due to requirement '__is_abstract(int)'}} \
+// expected-note at -1 {{'I' (aka 'int') is not abstract}} \
+// expected-note at -1 {{because it is not a struct or class type}}
+
+using Fty = void(); // function type
----------------
shafik wrote:

```suggestion
using Fty = void();
```
I don't think this comment adds anything b/c the diagnostic below gives the reason

https://github.com/llvm/llvm-project/pull/156199


More information about the cfe-commits mailing list