diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp index b1216a07f7624..dbd1e89070939 100644 --- a/clang/lib/Parse/ParseExprCXX.cpp +++ b/clang/lib/Parse/ParseExprCXX.cpp @@ -112,9 +112,20 @@ bool Parser::ParseOptionalCXXScopeSpecifier( assert(getLangOpts().CPlusPlus && "Call sites of this function should be guarded by checking for C++"); + // Has to happen before any "return false"s in this function. + bool CheckForDestructor = false; + if (MayBePseudoDestructor && *MayBePseudoDestructor) { + CheckForDestructor = true; + *MayBePseudoDestructor = false; + } + if (Tok.is(tok::annot_cxxscope)) { assert(!LastII && "want last identifier but have already annotated scope"); - assert(!MayBePseudoDestructor && "unexpected annot_cxxscope"); + if (CheckForDestructor && Tok.is(tok::tilde)) { + *MayBePseudoDestructor = true; + return false; + } + Actions.RestoreNestedNameSpecifierAnnotation(Tok.getAnnotationValue(), Tok.getAnnotationRange(), SS); @@ -122,13 +133,6 @@ bool Parser::ParseOptionalCXXScopeSpecifier( return false; } - // Has to happen before any "return false"s in this function. - bool CheckForDestructor = false; - if (MayBePseudoDestructor && *MayBePseudoDestructor) { - CheckForDestructor = true; - *MayBePseudoDestructor = false; - } - if (LastII) *LastII = nullptr; diff --git a/clang/test/Parser/gh220186.cpp b/clang/test/Parser/gh220186.cpp new file mode 100644 index 0000000000000..6ac4e8a1a3970 --- /dev/null +++ b/clang/test/Parser/gh220186.cpp @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify %s + +void foo1() { (auto()->bar::); } +// expected-error@-1 {{use of undeclared identifier 'bar'}} +// expected-error@-2 {{initializer for functional-style cast to 'auto' is empty}} +// expected-error@-3 {{expected unqualified-id}} + +void foo2() { (auto()->bar::~bar()); } +// expected-error@-1 {{use of undeclared identifier 'bar'}} +// expected-error@-2 {{initializer for functional-style cast to 'auto' is empty}}