https://github.com/TPPPP72 created https://github.com/llvm/llvm-project/pull/187921
Added extra checks to ParseDeclarationSpecifiers to prevent multiple type specifiers from being assigned to the same DeclSpec. >From ed7f18c03dc9dca1b94a97f7633858a1c79c7503 Mon Sep 17 00:00:00 2001 From: TPPPP72 <[email protected]> Date: Sun, 22 Mar 2026 16:39:31 +0800 Subject: [PATCH] [Clang] Fix crash when type-name is combined with class specifier in template argument --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Parse/ParseDecl.cpp | 12 ++++++++++++ clang/test/SemaTemplate/gh187664.cpp | 14 ++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 clang/test/SemaTemplate/gh187664.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index b92f1ab34aa51..1744357fde4bd 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -382,6 +382,7 @@ Bug Fixes to AST Handling - Fixed a bug where explicit nullability property attributes were not stored in AST nodes in Objective-C. (#GH179703) - Fixed a crash when parsing Doxygen ``@param`` commands attached to invalid declarations or non-function entities. (#GH182737) - Fixed a assertion when __block is used on global variables in C mode. (#GH183974) +- Fixed a crash when a type-name is incorrectly combined with a class specifier within a template default argument. (#GH187664) Miscellaneous Bug Fixes ^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 72935f427b7f8..6cab4bfe8123d 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -4456,6 +4456,18 @@ void Parser::ParseDeclarationSpecifiers( case tok::kw___interface: case tok::kw_union: { tok::TokenKind Kind = Tok.getKind(); + + // If already has a TST, skip it. + if (DS.getTypeSpecType() != DeclSpec::TST_unspecified) { + Diag(Tok, diag::err_invalid_decl_spec_combination) + << DeclSpec::getSpecifierName(DS.getTypeSpecType(), + Actions.getPrintingPolicy()); + + ConsumeToken(); + DS.SetTypeSpecError(); + continue; + } + ConsumeToken(); // These are attributes following class specifiers. diff --git a/clang/test/SemaTemplate/gh187664.cpp b/clang/test/SemaTemplate/gh187664.cpp new file mode 100644 index 0000000000000..441671c543f7e --- /dev/null +++ b/clang/test/SemaTemplate/gh187664.cpp @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -fblocks -fsyntax-only -verify %s + +class A { +public: + class B {}; +}; + +using X = A::B; + +class C { + template <typename T = X class A::B> void f(); + // expected-error@-1 {{cannot combine with previous 'type-name' declaration specifier}} + // expected-error@-2 {{expected ',' or '>' in template-parameter-list}} +}; _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
