[clang] [libcxx] Reapply "[Clang] Implement resolution for CWG1835 (#92957, #98547)" (PR #100425)

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 30 13:19:50 PDT 2024


================
@@ -1779,6 +1779,42 @@ void Parser::checkPotentialAngleBracket(ExprResult &PotentialTemplateName) {
                     Priority);
 }
 
+bool Parser::isMissingTemplateKeywordBeforeScope(bool AnnotateInvalid) {
+  assert(Tok.is(tok::coloncolon));
+  Sema::DisableTypoCorrectionRAII DTC(Actions);
+  ColonProtectionRAIIObject ColonProtection(*this);
+
+  SourceLocation StartLoc = Tok.getLocation();
+  if (TryAnnotateTypeOrScopeToken())
+    return true;
+  if (Tok.isSimpleTypeSpecifier(getLangOpts()))
+    return false;
+  CXXScopeSpec SS;
+  ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/nullptr,
+                                 /*ObjectHasErrors=*/false,
+                                 /*EnteringContext=*/false);
+  ExprResult Result = tryParseCXXIdExpression(SS, /*isAddressOfOperand=*/false);
----------------
zygoloid wrote:

I'm worried that this can perform semantic actions (for example, template instantiations) that we're not permitted to perform, resulting in errors outside the immediate context, instantiation of variables with initializers that would incorrectly run on program startup, or other misbehavior. Generally-speaking, it's not conforming to try to parse and semantically check code and then backtrack if it didn't work. We can do such things on error recovery paths, and we can do purely syntactic tentative parsing things (where it's OK to ask Sema about name lookup, but not OK to ask it to do more complicated things), but we can't do full semantic analysis tentatively.

https://github.com/llvm/llvm-project/pull/100425


More information about the cfe-commits mailing list