From a7539bc2d57d4484634eda94029376fe8a0a5de9 Mon Sep 17 00:00:00 2001 From: zebullon Date: Wed, 13 Nov 2024 20:23:49 +0900 Subject: [PATCH] Shame stash the parsedAttrs with Parser to deal with lifetime... --- clang/include/clang/Parse/Parser.h | 2 ++ clang/lib/Parse/ParseReflect.cpp | 13 +++++++------ clang/lib/Parse/Parser.cpp | 3 ++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h index 6f72000f195dab..4039604838f427 100644 --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -316,6 +316,8 @@ class Parser : public CodeCompletionHandler { /// Factory object for creating ParsedAttr objects. AttributeFactory AttrFactory; + /// FIXNE P3385 + ParsedAttributes Attrs; /// Gathers and cleans up TemplateIdAnnotations when parsing of a /// top-level declaration is finished. diff --git a/clang/lib/Parse/ParseReflect.cpp b/clang/lib/Parse/ParseReflect.cpp index 4de77b1682b9bc..9b0de2401b5cd1 100644 --- a/clang/lib/Parse/ParseReflect.cpp +++ b/clang/lib/Parse/ParseReflect.cpp @@ -83,21 +83,22 @@ ExprResult Parser::ParseCXXReflectExpression(SourceLocation OpLoc) { // Check for a standard attribute { - ParsedAttributes attrs(AttrFactory); - if (MaybeParseCXX11Attributes(attrs)) { + size_t last = Attrs.size(); + if (MaybeParseCXX11Attributes(Attrs)) { + size_t newLast = Attrs.size(); Diag(OperandLoc, diag::p3385_trace_attribute_parsed); // FIXME handle empty [[]] gracefully - if (attrs.empty()) { + if (last == newLast) { Diag(OperandLoc, diag::p3385_trace_empty_attributes_list); return ExprError(); } - if (attrs.size() > 1) { - Diag(OperandLoc, diag::p3385_err_attributes_list) << attrs.size(); + if (newLast - last > 1) { + Diag(OperandLoc, diag::p3385_err_attributes_list) << (newLast - last); return ExprError(); } - return Actions.ActOnCXXReflectExpr(OpLoc, &attrs.front()); + return Actions.ActOnCXXReflectExpr(OpLoc, &Attrs.back()); } } diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp index 7f7851cc451536..4e1bd266bd24f2 100644 --- a/clang/lib/Parse/Parser.cpp +++ b/clang/lib/Parse/Parser.cpp @@ -21,6 +21,7 @@ #include "clang/Parse/ParseDiagnostic.h" #include "clang/Parse/RAIIObjectsForParser.h" #include "clang/Sema/DeclSpec.h" +#include "clang/Sema/ParsedAttr.h" #include "clang/Sema/ParsedTemplate.h" #include "clang/Sema/Scope.h" #include "clang/Sema/SemaCodeCompletion.h" @@ -57,7 +58,7 @@ Parser::Parser(Preprocessor &pp, Sema &actions, bool skipFunctionBodies) : PP(pp), PreferredType(pp.isCodeCompletionEnabled()), Actions(actions), Diags(PP.getDiagnostics()), GreaterThanIsOperator(true), ColonIsSacred(false), InMessageExpression(false), - TemplateParameterDepth(0), ParsingInObjCContainer(false) { + TemplateParameterDepth(0), Attrs(AttrFactory), ParsingInObjCContainer(false) { SkipFunctionBodies = pp.isCodeCompletionEnabled() || skipFunctionBodies; Tok.startToken(); Tok.setKind(tok::eof);