Make copy-constructible classes copyable#8705
Open
pfultz2 wants to merge 5 commits into
Open
Conversation
| if (mReportProgressInterval < 0) | ||
| return; | ||
| mErrorLogger.reportProgress(mFilename, mStage.c_str(), 100); | ||
| mErrorLogger->reportProgress(mFilename, mStage.c_str(), 100); |
|
|
||
| // this shouldn't happen so output a debug warning | ||
| if (retry == 100 && mSettings.debugwarnings) { | ||
| if (retry == 100 && mSettings->debugwarnings) { |
| typeTok = typeTok->next(); | ||
| if (Token::Match(typeTok, ",|)")) { // #8333 | ||
| scope->symdb.mTokenizer.syntaxError(typeTok); | ||
| scope->symdb->mTokenizer->syntaxError(typeTok); |
|
|
||
| if (hasBody()) | ||
| scope->symdb.debugMessage(nameTok, "varid0", "Function::addArguments found argument \'" + nameTok->str() + "\' with varid 0."); | ||
| scope->symdb->debugMessage(nameTok, "varid0", "Function::addArguments found argument \'" + nameTok->str() + "\' with varid 0."); |
| // C4267 VC++ warning instead of several dozens lines | ||
| const int varIndex = varlist.size(); | ||
| varlist.emplace_back(token_, start_, end_, varIndex, access_, type_, scope_, scope_->symdb.mSettings); | ||
| varlist.emplace_back(token_, start_, end_, varIndex, access_, type_, scope_, scope_->symdb->mSettings); |
|
|
||
| // c++17 auto type deduction of braced init list | ||
| if (parent->isCpp() && mSettings.standards.cpp >= Standards::CPP17 && vt2 && Token::Match(parent->tokAt(-2), "auto %var% {")) { | ||
| if (parent->isCpp() && mSettings->standards.cpp >= Standards::CPP17 && vt2 && Token::Match(parent->tokAt(-2), "auto %var% {")) { |
added 2 commits
July 7, 2026 15:36
Contributor
Author
|
A lot of the changes are just mechanical changes of filter_arrows.py#!/usr/bin/env python3
import sys, re
AGGRESSIVE = any(a in ('-a', '--aggressive') for a in sys.argv[1:])
ANSI = re.compile(r'\x1b\[[0-9;?]*[a-zA-Z]')
def plain(s): return ANSI.sub('', s) # strip color for detection
def norm(l): return plain(l)[1:].replace('->', '.') # drop marker, normalize arrows
def hunk_is_noise(body):
removed = [norm(l) for l in body if plain(l).startswith('-')]
added = [norm(l) for l in body if plain(l).startswith('+')]
if not removed and not added:
return False
return sorted(removed) == sorted(added) # every change is arrow-only
def aggressive_body(body):
"""Cancel only the arrow-noise -/+ pairs, keep everything else."""
out, rem, add = [], [], []
def flush():
nonlocal rem, add
used = [False] * len(add)
anorm = [norm(a) for a in add]
for r in rem:
rn = norm(r); matched = False
for i in range(len(add)):
if not used[i] and anorm[i] == rn: # same once arrows normalized
used[i] = matched = True
break
if not matched:
out.append(r) # a real removal, keep it
out.extend(a for i, a in enumerate(add) if not used[i])
rem, add = [], []
for line in body:
pl = plain(line)
if pl.startswith('-'):
if add: flush() # new change block began
rem.append(line)
elif pl.startswith('+'):
add.append(line)
else:
flush(); out.append(line) # context / "\ No newline"
flush()
return out
out, file_header, file_header_emitted = [], [], False
hunk_header, hunk_body = None, []
def flush_hunk():
global hunk_header, hunk_body, file_header_emitted
if hunk_header is None:
return
if not hunk_is_noise(hunk_body): # drop fully-noise hunks entirely
body = aggressive_body(hunk_body) if AGGRESSIVE else hunk_body
if not file_header_emitted:
out.extend(file_header); file_header_emitted = True
out.append(hunk_header); out.extend(body)
hunk_header, hunk_body = None, []
for line in sys.stdin:
pl = plain(line)
if pl.startswith('diff --git') or pl.startswith('diff --cc'):
flush_hunk()
file_header, file_header_emitted = [line], False
elif pl.startswith('@@'):
flush_hunk()
hunk_header, hunk_body = line, []
elif hunk_header is not None:
hunk_body.append(line)
else:
file_header.append(line)
flush_hunk()
sys.stdout.write(''.join(out))And then you can view the diff locally with: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Lots of copy constructible classes were using const and ref members which makes the classes non-copyable due to no longer supporting a copy-assignment. I replaced the ref members with a
NonNullPtrclass which is kind of a mox ofgsl::non_nullandstd::reference_wrapper. This helps prevent assigning it as null since it only accepts a reference and not a pointer.Now this PR doesnt replace all reference members, just for the classes that are copy-constructible. If we want to convert a class back to use reference or const members then we can delete the copy constructor and assignment.
Furthermore, I enabled the clang-tidy check
cppcoreguidelines-avoid-const-or-ref-data-membersto check for these cases in the future. Here are some references explaining why this is bad practice:Beyond just being bad practice, this also has prevent me from doing certain things with the
ForwardAnalyzerrecently that might have improved it further such as joining or swaping a forked analyzer. I intentionally made these classes copyable for this reason(and were changed to non-copyable against my feedback as well). I understand that using references help prevent dereferencing a nullptr which is why I added aNonNullPtrclass instead of using raw pointers like previously.