diff --git a/src/Func.cc b/src/Func.cc index 4d2abf9f41..6bfbf8c458 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -883,9 +883,7 @@ function_ingredients::function_ingredients(ScopePtr scope, StmtPtr body, if ( a->Tag() == ATTR_IS_USED ) { // Associate this with the identifier, too. - std::vector used_attr; - used_attr.emplace_back(make_intrusive(ATTR_IS_USED)); - id->AddAttrs(make_intrusive(used_attr, nullptr, false, true)); + id->AddAttr(make_intrusive(ATTR_IS_USED)); break; } } diff --git a/src/ID.cc b/src/ID.cc index bfc4f57ea1..8fc6d3d0b6 100644 --- a/src/ID.cc +++ b/src/ID.cc @@ -311,8 +311,7 @@ void ID::MakeDeprecated(ExprPtr deprecation) if ( IsDeprecated() ) return; - std::vector attrv{make_intrusive(ATTR_DEPRECATED, std::move(deprecation))}; - AddAttrs(make_intrusive(std::move(attrv), GetType(), false, IsGlobal())); + AddAttr(make_intrusive(ATTR_DEPRECATED, std::move(deprecation))); } std::string ID::GetDeprecationWarning() const @@ -329,6 +328,13 @@ std::string ID::GetDeprecationWarning() const return util::fmt("deprecated (%s): %s", Name(), result.c_str()); } +void ID::AddAttr(AttrPtr a, bool is_redef) + { + std::vector attrv{std::move(a)}; + auto attrs = make_intrusive(std::move(attrv), GetType(), false, IsGlobal()); + AddAttrs(std::move(attrs), is_redef); + } + void ID::AddAttrs(AttributesPtr a, bool is_redef) { if ( attrs ) @@ -354,10 +360,7 @@ void ID::SetOption() // option implied redefinable if ( ! IsRedefinable() ) - { - std::vector attrv{make_intrusive(ATTR_REDEF)}; - AddAttrs(make_intrusive(std::move(attrv), GetType(), false, IsGlobal())); - } + AddAttr(make_intrusive(ATTR_REDEF)); } void ID::EvalFunc(ExprPtr ef, ExprPtr ev) diff --git a/src/ID.h b/src/ID.h index 47322d78a2..682f865a09 100644 --- a/src/ID.h +++ b/src/ID.h @@ -116,6 +116,7 @@ public: bool IsRedefinable() const; void SetAttrs(AttributesPtr attr); + void AddAttr(AttrPtr a, bool is_redef = false); void AddAttrs(AttributesPtr attr, bool is_redef = false); void RemoveAttr(AttrTag a); void UpdateValAttrs(); diff --git a/src/RuleCondition.cc b/src/RuleCondition.cc index 5ef39b6097..e73eaee85a 100644 --- a/src/RuleCondition.cc +++ b/src/RuleCondition.cc @@ -181,9 +181,7 @@ RuleConditionEval::RuleConditionEval(const char* func) "and a 'string' type", func); - std::vector attrv{make_intrusive(ATTR_IS_USED, nullptr)}; - id->AddAttrs( - make_intrusive(std::move(attrv), id->GetType(), false, id->IsGlobal())); + id->AddAttr(make_intrusive(ATTR_IS_USED)); } } diff --git a/src/script_opt/CPP/RuntimeInitSupport.cc b/src/script_opt/CPP/RuntimeInitSupport.cc index 3f74c24f1e..45db298044 100644 --- a/src/script_opt/CPP/RuntimeInitSupport.cc +++ b/src/script_opt/CPP/RuntimeInitSupport.cc @@ -109,11 +109,7 @@ void activate_bodies__CPP(const char* fn, const char* module, bool exported, Typ } if ( ! fg->GetAttr(ATTR_IS_USED) ) - { - vector used_attr; - used_attr.emplace_back(make_intrusive(ATTR_IS_USED)); - fg->AddAttrs(make_intrusive(used_attr, nullptr, false, true)); - } + fg->AddAttr(make_intrusive(ATTR_IS_USED)); auto v = fg->GetVal(); if ( ! v )