diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 3e84e25f360fa..b4f3846e81339 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -931,6 +931,7 @@ Bug Fixes to C++ Support - Improved handling of variables with ``consteval`` constructors, to consistently treat the initializer as manifestly constant-evaluated. (#GH135281) +- Fix a crash in the presence of invalid base classes. (#GH147186) Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index eae8281964692..59e6e0af4b5b0 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -2252,7 +2252,7 @@ void Parser::ParseBaseClause(Decl *ClassDecl) { while (true) { // Parse a base-specifier. BaseResult Result = ParseBaseSpecifier(ClassDecl); - if (Result.isInvalid()) { + if (!Result.isUsable()) { // Skip the rest of this base specifier, up until the comma or // opening brace. SkipUntil(tok::comma, tok::l_brace, StopAtSemi | StopBeforeMatch); diff --git a/clang/test/SemaCXX/invalid-base-inheritance.cpp b/clang/test/SemaCXX/invalid-base-inheritance.cpp new file mode 100644 index 0000000000000..b9615a5666970 --- /dev/null +++ b/clang/test/SemaCXX/invalid-base-inheritance.cpp @@ -0,0 +1,16 @@ +// Tests that invalid base-specifiers no longer crash the compiler. +// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s + +namespace GH147186 { + +class X; // expected-note {{forward declaration of 'GH147186::X'}} expected-note {{forward declaration of 'GH147186::X'}} + +class A : X { // expected-error {{base class has incomplete type}} +}; + +class Y : int { // expected-error {{expected class name}} +}; + +class Z : X*, virtual int { // expected-error {{base class has incomplete type}} expected-error {{expected class name}} +}; +}