@@ -21,20 +21,36 @@ ExprResult Parser::ParseCXXReflectExpression(SourceLocation DoubleCaretLoc) {
2121 EnterExpressionEvaluationContext Unevaluated (
2222 Actions, Sema::ExpressionEvaluationContext::Unevaluated);
2323
24+ CXXScopeSpec SS;
25+ if (ParseOptionalCXXScopeSpecifier (SS, /* ObjectType=*/ nullptr ,
26+ /* ObjectHasErrors=*/ false ,
27+ /* EnteringContext=*/ false )) {
28+ SkipUntil (tok::semi, StopAtSemi | StopBeforeMatch);
29+ return ExprError ();
30+ }
31+
2432 SourceLocation OperandLoc = Tok.getLocation ();
33+ TentativeParsingAction TPA (*this );
2534
26- {
27- TentativeParsingAction TPA (*this );
28- // global namespace ::
29- if (Tok.is (tok::coloncolon)) {
30- ConsumeToken ();
31- TPA.Commit ();
32- Decl *TUDecl = Actions.getASTContext ().getTranslationUnitDecl ();
33- return Actions.ActOnCXXReflectExpr (DoubleCaretLoc, SourceLocation (),
34- TUDecl);
35- }
36- TPA.Revert ();
35+ // Next, check for an unqualified-id.
36+ if (Tok.isOneOf (tok::identifier, tok::kw_operator, tok::kw_template,
37+ tok::tilde, tok::annot_template_id)) {
38+ // TODO(reflection) : support parsing for
39+ // - type-name::
40+ // - nested-name-specifier identifier ::
41+ // - namespace-name ::
42+ // - nested-name-specifier template_opt simple-template-id
43+ Diag (OperandLoc, diag::err_cannot_reflect_operand);
44+ return ExprError ();
45+ } else if (SS.isValid () &&
46+ SS.getScopeRep ().getKind () == NestedNameSpecifier::Kind::Global) {
47+ // global namespace ::.
48+ TPA.Commit ();
49+ Decl *TUDecl = Actions.getASTContext ().getTranslationUnitDecl ();
50+ return Actions.ActOnCXXReflectExpr (DoubleCaretLoc, SourceLocation (),
51+ TUDecl);
3752 }
53+ TPA.Revert ();
3854
3955 if (isCXXTypeId (TentativeCXXTypeIdContext::AsReflectionOperand)) {
4056 TypeResult TR = ParseTypeName (/* TypeOf=*/ nullptr );
0 commit comments