[all-commits] [llvm/llvm-project] acf5ad: [Clang][Sema] Diagnose current instantiation used ...

Krystian Stasiowski via All-commits all-commits at lists.llvm.org
Mon May 20 11:45:22 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: acf5ad2a4ed9bf94b03d18ccddce7710e721dc6c
      https://github.com/llvm/llvm-project/commit/acf5ad2a4ed9bf94b03d18ccddce7710e721dc6c
  Author: Krystian Stasiowski <sdkrystian at gmail.com>
  Date:   2024-05-20 (Mon, 20 May 2024)

  Changed paths:
    M clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-member-init-no-crash.cpp
    M clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-member-init.cpp
    M clang/docs/ReleaseNotes.rst
    M clang/include/clang/Basic/DiagnosticSemaKinds.td
    M clang/lib/AST/Type.cpp
    M clang/lib/Sema/SemaDeclCXX.cpp
    M clang/test/CXX/basic/basic.lookup/basic.lookup.qual/class.qual/p2.cpp
    A clang/test/CXX/class.derived/class.derived.general/p2.cpp
    M clang/test/SemaTemplate/dependent-names.cpp
    M clang/test/SemaTemplate/destructor-template.cpp
    M clang/test/SemaTemplate/typo-dependent-name.cpp

  Log Message:
  -----------
  [Clang][Sema] Diagnose current instantiation used as an incomplete base class (#92597)

Consider the following:
```
template<typename T>
struct A
{
    struct B : A { };
};
```
According to [class.derived.general] p2:
> [...] A _class-or-decltype_ shall denote a (possibly cv-qualified)
class type that is not an incompletely defined class; any cv-qualifiers
are ignored. [...]

Although GCC and EDG rejects this, Clang accepts it. This is incorrect,
as `A` is incomplete within its own definition (outside of a
complete-class context). This patch correctly diagnoses instances where
the current instantiation is used as a base class before it is complete.

Conversely, Clang erroneously rejects the following:
```
template<typename T>
struct A 
{
    struct B;

    struct C : B { };

    struct B : C { }; // error: circular inheritance between 'C' and 'A::B'
};
```
Though it may seem like no valid specialization of this template can be
instantiated, an explicit specialization of either member classes for an
implicit instantiated specialization of `A` would permit the definition
of the other member class to be instantiated, e.g.:
```
template<>
struct A<int>::B { };

A<int>::C c; // ok
```
So this patch also does away with this error. This means that circular
inheritance is diagnosed during instantiation of the definition as a
consequence of requiring the base class type to be complete (matching
the behavior of GCC and EDG).



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list