Skip to content

Commit 0645128

Browse files
committed
[Clang] prevent crash on invalid nested name specifiers with a single colon
1 parent 8baa5bf commit 0645128

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,8 @@ Crash and bug fixes
719719
``[[assume(expr)]]`` attribute was enclosed in parentheses. (#GH151529)
720720
- Fixed a crash when parsing ``#embed`` parameters with unmatched closing brackets. (#GH152829)
721721
- Fixed a crash when compiling ``__real__`` or ``__imag__`` unary operator on scalar value with type promotion. (#GH160583)
722+
- Fixed a crash when parsing invalid nested name specifier sequences
723+
containing a single colon. (#GH167905)
722724

723725
Improvements
724726
^^^^^^^^^^^^

clang/lib/Parse/ParseTentative.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,8 @@ Parser::isCXXDeclarationSpecifier(ImplicitTypenameContext AllowImplicitTypename,
10631063
return TPResult::False;
10641064
}
10651065

1066-
if (Next.isNot(tok::coloncolon) && Next.isNot(tok::less)) {
1066+
if (Next.isNot(tok::coloncolon) && Next.isNot(tok::less) &&
1067+
Next.isNot(tok::colon)) {
10671068
// Determine whether this is a valid expression. If not, we will hit
10681069
// a parse error one way or another. In that case, tell the caller that
10691070
// this is ambiguous. Typo-correct to type and expression keywords and
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %clang_cc1 -fsyntax-only -verify %s
2+
3+
namespace a { b c ( a:c::
4+
// expected-error@-1 {{unknown type name 'b'}}
5+
// expected-error@-2 {{unexpected ':' in nested name specifier; did you mean '::'?}}
6+
// expected-error@-3 {{no member named 'c' in namespace 'a'}}
7+
// expected-error@-4 {{expected ';' after top level declarator}}
8+
// expected-note@-5 {{to match this '{'}}
9+
// expected-error@+1 {{expected unqualified-id}} \
10+
// expected-error@+1 {{expected '}'}}

0 commit comments

Comments
 (0)