[PATCH] D113474: [clang] Don't crash on an incomplete-type base specifier in template context.

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 9 07:36:23 PST 2021


sammccall accepted this revision.
sammccall added inline comments.


================
Comment at: clang/test/SemaCXX/base-class-ambiguity-check.cpp:15
+  // Should not crash on an incomplete-type and dependent base specifier.
+  struct Derived : Base1, Base2 {}; // expected-error {{implicit instantiation of undefined member 'Foo2<int>::Base1'}} \
+                                       expected-error {{implicit instantiation of undefined member 'Foo2<int>::Base2'}}
----------------
hokein wrote:
> The diagnostic is suboptimal (I'd expect it is "invalid use of incomplete type"), but it is not regression, clang shows the same diagnostics for the following non-crash case:
> 
> ```
> template <typename T> struct Foo2 {
>   struct Base1;
>   struct Derived : Base1 {};
> }
> ```
Or even
```
template <int> struct X;
X<42> y;
```

I think the diagnostic is OK - it's diagnosing why the type *is* incomplete, rather than why the type *may not* be complete.

Typical use of this pattern would be to provide an out-of-line definition template:

```
template <typename T> struct Foo2<T>::Base1 {
  T contents;
}
```

in which case instantiation is the right idea.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113474/new/

https://reviews.llvm.org/D113474



More information about the cfe-commits mailing list