Skip to content

Commit

Permalink
Merge pull request #461 from andreasfertig/fixIssue456
Browse files Browse the repository at this point in the history
Fixed #456: Correct replacement of a `VarDecl` with attributes.
  • Loading branch information
andreasfertig committed May 1, 2022
2 parents da5727c + 374b703 commit 745269a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion GlobalVariableHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,18 @@ void GlobalVariableHandler::run(const MatchFinder::MatchResult& result)
if(const auto* matchedDecl = result.Nodes.getNodeAs<VarDecl>("varDecl")) {
OutputFormatHelper outputFormatHelper{};

const auto sr = GetSourceRangeAfterSemi(matchedDecl->getSourceRange(), result, RequireSemi::Yes);
// Take a preceding attribute into account
const auto sr = [&] {
auto tmpSr = GetSourceRangeAfterSemi(matchedDecl->getSourceRange(), result, RequireSemi::Yes);

const auto& attrs = matchedDecl->attrs();
SourceLocation start = tmpSr.getBegin();

std::for_each(
attrs.begin(), attrs.end(), [&](const auto* attr) { start = std::min(attr->getLocation(), start); });

return SourceRange{start, tmpSr.getEnd()};
}();

// Check whether we already have rewritten this location. If so, insert the text after the location. This is the
// case for:
Expand Down
2 changes: 1 addition & 1 deletion tests/AlignAsTest.expect
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ struct alignas(16) AlignedStruct



alignas(128) alignas(128) char alignedArray[128];
alignas(128) char alignedArray[128];


template <typename... Ts>
Expand Down

0 comments on commit 745269a

Please sign in to comment.