Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,7 @@ Bug Fixes to C++ Support
- Improved handling of variables with ``consteval`` constructors, to
consistently treat the initializer as manifestly constant-evaluated.
(#GH135281)
- Switch `ParseBaseClause` to use `BaseResult::isUsable()` instead of `isInvalid()`, fixing dropped or mis-parsed base specifiers in C++ classes. (#GH147186)

Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
5 changes: 4 additions & 1 deletion clang/lib/Parse/ParseDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2252,7 +2252,10 @@ void Parser::ParseBaseClause(Decl *ClassDecl) {
while (true) {
// Parse a base-specifier.
BaseResult Result = ParseBaseSpecifier(ClassDecl);
if (Result.isInvalid()) {
// Skip any base-specifier we couldn’t actually build into a usable
// CXXBaseSpecifier (covers both syntactic invalidity and
// other un-usable cases).
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);
Expand Down
13 changes: 13 additions & 0 deletions clang/test/SemaCXX/invalid-base-inheritance.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Tests that invalid base-specifiers no longer crash the compiler.
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s

class X; // expected-note {{forward declaration of 'X'}} expected-note {{forward declaration of '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}}
};