Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,8 @@ Crash and bug fixes
``[[assume(expr)]]`` attribute was enclosed in parentheses. (#GH151529)
- Fixed a crash when parsing ``#embed`` parameters with unmatched closing brackets. (#GH152829)
- Fixed a crash when compiling ``__real__`` or ``__imag__`` unary operator on scalar value with type promotion. (#GH160583)
- Fixed a crash when parsing invalid nested name specifier sequences
containing a single colon. (#GH167905)

Improvements
^^^^^^^^^^^^
Expand Down
8 changes: 7 additions & 1 deletion clang/include/clang/Lex/Token.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,19 @@ class Token {
/// is/isNot - Predicates to check if this token is a specific kind, as in
/// "if (Tok.is(tok::l_brace)) {...}".
bool is(tok::TokenKind K) const { return Kind == K; }
bool isNot(tok::TokenKind K) const { return Kind != K; }
template <typename... Ts> bool isOneOf(Ts... Ks) const {
static_assert(sizeof...(Ts) > 0,
"requires at least one tok::TokenKind specified");
return (is(Ks) || ...);
}

bool isNot(tok::TokenKind K) const { return Kind != K; }
template <typename... Ts> bool isNoneOf(Ts... Ks) const {
static_assert(sizeof...(Ts) > 0,
"requires at least one tok::TokenKind specified");
return (isNot(Ks) && ...);
}

/// Return true if this is a raw identifier (when lexing
/// in raw mode) or a non-keyword identifier (when lexing in non-raw mode).
bool isAnyIdentifier() const {
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Parse/ParseTentative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ Parser::isCXXDeclarationSpecifier(ImplicitTypenameContext AllowImplicitTypename,
return TPResult::False;
}

if (Next.isNot(tok::coloncolon) && Next.isNot(tok::less)) {
if (Next.isNoneOf(tok::coloncolon, tok::less, tok::colon)) {
// Determine whether this is a valid expression. If not, we will hit
// a parse error one way or another. In that case, tell the caller that
// this is ambiguous. Typo-correct to type and expression keywords and
Expand Down
10 changes: 10 additions & 0 deletions clang/test/Parser/cxx-nested-name-spec.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// 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 '}'}}
Loading