llvm-project/clang/test/Parser/cxx-nested-name-spec.cpp
Oleksandr T. c128fd9beb
[Clang] prevent crash on invalid nested name specifiers with a single colon (#169246)
Fixes #167905

--- 

This patch addresses an issue where invalid nested name specifier
sequences containing a single colon (`a:c::`) could be treated during
recovery as valid scope specifiers, which in turn led to a crash


c543615744/clang/lib/Parse/ParseExprCXX.cpp (L404-L418)


For malformed inputs like `a:c::`, the single colon recovery incorrectly
triggers and produces an `annot_cxxscope`. When tentative parsing later
runs


996213c6ea/clang/lib/Parse/ParseTentative.cpp (L1739-L1740)

the classifier returns `Ambiguous`, which doesn't stop parsing. The
parser then enters the


996213c6ea/clang/lib/Parse/ParseTentative.cpp (L1750-L1752)

and consumes the invalid scope annotation, eventually reaching `EOF` and
crashing.
2025-12-03 17:24:33 +02:00

11 lines
461 B
C++

// RUN: %clang_cc1 -fsyntax-only -verify %s
namespace a { b c ( a:c::
// expected-error@-1 {{unknown type name 'b'}}
// expected-error@-2 {{unexpected ':' in nested name specifier; did you mean '::'?}}
// expected-error@-3 {{no member named 'c' in namespace 'a'}}
// expected-error@-4 {{expected ';' after top level declarator}}
// expected-note@-5 {{to match this '{'}}
// expected-error@+1 {{expected unqualified-id}} \
// expected-error@+1 {{expected '}'}}