Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clang-tidy] Remove enforcement of rule C.48 from cppcoreguidelines-p… #80193

Closed
wants to merge 128 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
128 commits
Select commit Hold shift + click to select a range
bfa4ea3
[clang-tidy] Remove enforcement of rule C.48 from cppcoreguidelines-p…
Jan 31, 2024
3aba4c7
Improve Release Notes
Feb 1, 2024
6c66b9f
[flang] Downgrade a too-strong error message to a warning (#80095)
klausler Jan 31, 2024
017d1ec
Revert "[lldb][progress][NFC] Add unit test for progress reports (#79…
chelcassanova Jan 31, 2024
086d2b2
Revert "Add one more verbose watchpoint logging for arm-ubuntu"
jasonmolenda Jan 31, 2024
b526b09
Revert "Enable verbose watch log channel to debug x86-64-debian bot"
jasonmolenda Jan 31, 2024
8a32094
Revert "Add logging to WatchpointAlgorithm"
jasonmolenda Jan 31, 2024
508db2a
Revert "Collecting more logging to debug CI bots"
jasonmolenda Jan 31, 2024
c24a298
Revert "Add extra printing to TestWatchpointCount.py to debug CI fail"
jasonmolenda Jan 31, 2024
1f24bce
Revert "[lldb] Add support for large watchpoints in lldb (#79962)"
jasonmolenda Jan 31, 2024
cf7ad10
[gn build] Port d347c564299e
llvmgnsyncbot Jan 31, 2024
aa7a06b
[clang][DependencyScanner] Remove unused -fmodule-map-file arguments …
Bigcheese Jan 31, 2024
a2639e3
[LSR] Add a test case mentioned in review
preames Jan 31, 2024
808404d
[Github] Build PGO optimized toolchain in container (#80096)
boomanaiden154 Jan 31, 2024
a0d59cc
[ORC] Merge MaterializationResponsibility notifyEmitted and addDepend…
lhames Jan 31, 2024
12bab4c
[libc] Fix condition ordering in scanf (#80083)
michaelrj-google Jan 31, 2024
1e15177
[AIX] [XCOFF] Add support for common and local common symbols in the …
syzaara Jan 31, 2024
936d1c6
[analyzer] Unbreak [[clang::suppress]] on checkers without decl-with-…
haoNoQ Jan 31, 2024
4fbfa9c
[AArch64][SVE2] Generate urshr rounding shift rights (#78374)
UsmanNadeem Jan 31, 2024
55639fa
AMDGPU/NFC: Add predicate for supporting buffer/flat/global f64 atomi…
kzhuravl Jan 31, 2024
27b3ae2
[flang][hlfir][NFC] Fix typo
clementval Jan 31, 2024
27aaed1
[NVPTX] improve Boolean ISel (#80166)
AlexMaclean Jan 31, 2024
005c850
[RISCV] Improve legalization of e8 m8 VL>256 shuffles (#79330)
preames Jan 31, 2024
2571532
[lldb][NFCI] Remove m_being_created from Breakpoint classes (#79716)
bulbazord Jan 31, 2024
789df89
[lsr][term-fold] Restrict transform to low cost expansions (#74747)
preames Jan 31, 2024
bd380c9
Partial revert "[HIP] Fix -mllvm option for device lld linker" (#80202)
yxsamliu Jan 31, 2024
debc9d6
Reland "[lldb][progress][NFC] Add unit test for progress reports (#79…
chelcassanova Jan 31, 2024
c82054b
[WebAssembly] avoid to enable explicit disabled feature (#80094)
HerrCai0907 Jan 31, 2024
f0c2365
Revert "Reland "[lldb][progress][NFC] Add unit test for progress repo…
chelcassanova Jan 31, 2024
7d50a6b
[RISCV] Use Zacas for AtomicRMWInst::Nand i32 and XLen. (#80119)
topperc Jan 31, 2024
58129e7
[libc][docs] fix stdbit.h docs (#80070)
nickdesaulniers Jan 31, 2024
21c0416
[libc] Fix read under msan (#80203)
michaelrj-google Feb 1, 2024
07ac792
[mlir][Vector] Add support for sub-byte transpose emulation (#80110)
dcaballe Feb 1, 2024
a433b20
[mlir][arith] Improve `truncf` folding (#80206)
kuhar Feb 1, 2024
20f9114
[llvm-objcopy][test] Use llvm-readelf instead for clearer visualizati…
kongy Feb 1, 2024
cc2ab4f
[clang][NFC] Move isSimpleTypeSpecifier() from Sema to Token (#80101)
owenca Feb 1, 2024
c320e26
[clang-format] Simplify the AfterPlacementOperator option (#79796)
owenca Feb 1, 2024
bc617fa
[clang][dataflow][NFC] Rename a confusingly named variable. (#80182)
martinboehme Feb 1, 2024
65ac8a2
[clang][dataflow] Display line numbers in the HTML logger timeline. (…
martinboehme Feb 1, 2024
ee20b59
[lldb] Add support for large watchpoints in lldb (#79962)
jasonmolenda Feb 1, 2024
6670041
[gn build] Port 147d7a64f849
llvmgnsyncbot Feb 1, 2024
713f6d5
[SelectOpt] Print instruction instead of pointer
wangpc-pp Jan 31, 2024
5df7f19
[llvm-gsymutil] Print one-time DWO file missing warning under --quiet…
kusmour Feb 1, 2024
4547aa5
Add debug prints to diagnose a crash on arm-ubuntu bot
jasonmolenda Feb 1, 2024
d7992b0
[X86][NFC] Simplify the code for memory fold
KanRobert Feb 1, 2024
26e81a2
[C++20] [Modules] Introduce -fskip-odr-check-in-gmf (#79959)
ChuanqiXu9 Feb 1, 2024
e4eac74
[clang-tidy] Add AllowStringArrays option to modernize-avoid-c-arrays…
PiotrZSL Feb 1, 2024
ddab122
[clang-format] Allow decltype in requires clause (#78847)
rymiel Feb 1, 2024
7566cf5
Skip 2 of the three test sets to narrow down the arm-ubuntu
jasonmolenda Feb 1, 2024
dbab827
[clang][Interp] complex binary operators aren't always initializing
tbaederr Jan 31, 2024
5ab0e77
[Github] Build stage2-clang-bolt target for CI container
boomanaiden154 Feb 1, 2024
3250fb1
[clang][Interp] Handle imaginary literals (#79130)
tbaederr Feb 1, 2024
a141e1a
[X86][CodeGen] Set mayLoad = 1 for LZCNT/POPCNT/TZCNTrm_(EVEX|NF)
KanRobert Feb 1, 2024
613bc76
Uncomment the 2GB max tests and see if that works on arm-ubuntu
jasonmolenda Feb 1, 2024
3ac51db
[clang][Interp] Protect Inc/Dec ops against dummy pointers
tbaederr Jan 31, 2024
9e1f497
[clang][Interp][NFC] Remove unused RecordScope
tbaederr Feb 1, 2024
dba08b9
[clang][Interp] Support GenericSelectionExprs
tbaederr Jan 31, 2024
2c59312
Trying to refine which test is crashing on arm-ubuntu.
jasonmolenda Feb 1, 2024
5785171
[mlir] Use `create` instead of `createOrFold` for ConstantOp as foldi…
nujaa Feb 1, 2024
159772a
[GlobalISel][TableGen] Support Intrinsics in MIR Patterns (#79278)
Pierre-vh Feb 1, 2024
9c87eea
[IR] Use range-based for loops (NFC)
kazutakahirata Feb 1, 2024
9635078
[llvm] Use StringRef::starts_with (NFC)
kazutakahirata Feb 1, 2024
7227d1c
[clang] Use StringRef::starts_with (NFC)
kazutakahirata Feb 1, 2024
f7f6774
Done iterating with arm-ubuntu bot, I see the problem test.
jasonmolenda Feb 1, 2024
506db29
Skip two WatchpointAlgorithm tests for 32-bit lldb's
jasonmolenda Feb 1, 2024
b8b75d0
[mlir][Transforms] `GreedyPatternRewriteDriver`: Hash ops separately …
matthias-springer Feb 1, 2024
6c05e44
[flang][NFC] Cache derived type translation in lowering (#80179)
jeanPerier Feb 1, 2024
e53925d
[Clang][test] Limit library search when linking shared lib (#80253)
apolloww Feb 1, 2024
5febe1d
[mlir][EmitC] Add func, call and return operations and conversions (…
marbre Feb 1, 2024
9e1e479
[bazel] Add missing header for 7ec996d4c5c30083b070be4898140440094e6b97
d0k Feb 1, 2024
ac02030
[bazel] Merge TableGenGlobalISel into the tablegen target
d0k Feb 1, 2024
35bc0e9
[bazel] Put back the pieces of TableGenGlobalISel that unittests depe…
d0k Feb 1, 2024
ba941b6
[llvm-exegesis] Replace --num-repetitions with --min-instructions (#7…
boomanaiden154 Feb 1, 2024
46aa7b0
[bazel] Fix a typo from e7d40a87ff230528131541f6ac17a2e1a7dc78e1
d0k Feb 1, 2024
6c15f28
[flang][HLFIR] Relax verifiers of intrinsic operations (#80132)
tblah Feb 1, 2024
79b87d1
[Clang][AArch64] Add ACLE macros for FEAT_PAuth_LR (#80163)
pratlucas Feb 1, 2024
9cb5a1e
[HWASAN] Remove DW_OP_LLVM_tag_offset from DIExpression::isImplicit (…
OCHyams Feb 1, 2024
f976d4e
[GitHub][workflows] Reflow some text in buildbot info PR comment
DavidSpickett Feb 1, 2024
759c252
[AMDGPU] Check wavefrontsize for GFX11 WMMA builtins (#79980)
jayfoad Feb 1, 2024
1db998a
[SCEVExp] Keep NUW/NSW if both original inc and isomporphic inc agree…
fhahn Feb 1, 2024
0c603d2
[libc++][memory] P2652R2: Disallow Specialization of `allocator_trait…
H-G-Hristov Feb 1, 2024
595380a
[ARM] Add ctpop codegen tests
RKSimon Feb 1, 2024
3c0a2b0
[IndVars] Add tests for #79861 (NFC)
nikic Feb 1, 2024
1528387
[RISCV][NFC] Simplify calls.ll and autogenerate checks for tail-calls.ll
wangpc-pp Feb 1, 2024
13daf9f
[openmp] On Windows, fix standalone cmake build (#80174)
aganea Feb 1, 2024
b54c6ff
[AMDGPU] Prefer `s_memtime` for `readcyclecounter` on GFX10 (#80211)
jhuber6 Feb 1, 2024
46f19cd
[AArch64] Replace LLVM IR function attributes for PSTATE.ZA. (#79166)
sdesmalen-arm Feb 1, 2024
8829825
[AArch64] Alter latency of FCSEL under Cortex-A510 (#80178)
davemgreen Feb 1, 2024
0f6bd0b
[mlir][scf] Considering defining operators of indices when fusing scf…
Hsiangkai Feb 1, 2024
5c807a7
[MIRPrinter] Don't print line break when there is no instructions (NF…
DianQK Feb 1, 2024
0fe0fa4
[SLP][NFC]Introduce and use computeCommonAlignment function, NFC.
alexey-bataev Feb 1, 2024
29ccc91
[AIX][TLS] Optimize the small local-exec access sequence for non-zero…
amy-kwan Feb 1, 2024
b7d6f34
[PowerPC] Fix -Wunused-variable in PPCAsmPrinter.cpp and PPCISelDAGTo…
DamonFool Feb 1, 2024
009fdda
[LoopUnroll] Add test for #80289 (NFC)
nikic Feb 1, 2024
095c1ac
[LoopUnroll] Fix missing sign extension
nikic Feb 1, 2024
0f4efbe
[BOLT] Add extra staleness logging (#80225)
aaupov Feb 1, 2024
1334f50
[HIP] fix HIP detection for /usr (#80190)
yxsamliu Feb 1, 2024
af5530a
[mlir][scf] Add reductions support to `scf.parallel` fusion (#75955)
Hardcode84 Feb 1, 2024
2efccb3
[LSR] Add tests for restricting term-fold budget based on exact trip …
preames Feb 1, 2024
d8ce5ba
[X86] X86FixupVectorConstants.cpp - refactor constant search loop to …
RKSimon Feb 1, 2024
90e91d0
[Sema] Fix crash in __datasizeof with unknown types (#80300)
ilya-biryukov Feb 1, 2024
b3afa26
[Clang][Parse] Diagnose member template declarations with multiple de…
sdkrystian Feb 1, 2024
48a20b3
[AArch64] Make +pauth enabled in Armv8.3-a by default (#78027)
atrosinenko Feb 1, 2024
5058ff6
[BOLT][NFC] Factor out RI::disassemblePLTInstruction (#80302)
aaupov Feb 1, 2024
2b3ca38
[llvm-objdump][AMDGPU] Pass ELF ABIVersion through disassembler (#78907)
epilk Feb 1, 2024
505f4f2
[flang] Fix passing NULL to OPTIONAL procedure pointers (#80267)
jeanPerier Feb 1, 2024
ed72324
Aggregate errors from llvm-dwarfdump --verify (#79648)
kevinfrei Feb 1, 2024
332d2bc
[Clang][NFC] Remove TemplateArgumentList::OnStack (#79760)
sdkrystian Feb 1, 2024
8cc91c6
[libc][NFC] Refactor FLAGS expansion using cmake_language(CALL ...). …
lntue Feb 1, 2024
9994354
[NFC] Reorder test lines in arith-fp-frem.ll (#79991)
paschalis-mpeis Feb 1, 2024
caf7c5f
[SLP][NFC]Add tests with strided loads, NFC.
alexey-bataev Feb 1, 2024
595ea85
[clang-format] Handles Elaborated type specifier for enum in trailing…
XDeme1 Feb 1, 2024
5e0962a
Fix debug info size statistics for split dwarf (#80218)
jeffreytan81 Feb 1, 2024
674c1a6
[libc] Update libc_errno to work correctly in both overlay and full b…
lntue Feb 1, 2024
efc3b3d
[AMDGPU] Mark PC_ADD_REL_OFFSET rematerializable (#79674)
yxsamliu Feb 1, 2024
d970ab0
[libc] Fix wrong errno number in tls_test. (#80312)
lntue Feb 1, 2024
c79fbe1
Fix Passing TargetOptions by Value in TargetMachines for AMDGPU (#79866)
matinraayai Feb 1, 2024
2aee881
[OpenMP] Move unsupported structured bindings diagnostic (#80216)
mikerice1969 Feb 1, 2024
ba7a220
[libc++][NFC] Remove <experimental/__memory> (#80194)
philnik777 Feb 1, 2024
cf06eed
[libc] implement stdc_leading_ones (C23) (#80082)
nickdesaulniers Feb 1, 2024
0a934f3
[RISCV] Support constraint "s" (#80201)
MaskRay Feb 1, 2024
93ceb8f
[lld-macho] Make ObjC category checker print the source file name of …
alx32 Feb 1, 2024
22493b1
[OpenMP] Fix build breakage (NFC) (#80313)
kkwli Feb 1, 2024
9230a36
[mlir][EmitC] Harmonize include guard (NFC)
marbre Feb 1, 2024
7cbc43a
[SLP][NFC]Add some extra checks/reorganize the code to improve compil…
alexey-bataev Feb 1, 2024
fe5ae8f
[RISCV][MC] MC layer support for the experimental zalasr extension (#…
mehnadnerd Feb 1, 2024
edac587
[clang-tidy] Remove enforcement of rule C.48 from cppcoreguidelines-p…
Jan 31, 2024
b5bfeaa
Improve Release Notes
Feb 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,6 @@ static bool isNoReturnCallStatement(const Stmt *S) {
return Func->isNoReturn();
}

static bool isLiteral(const Expr *E) {
return isa<StringLiteral, CharacterLiteral, IntegerLiteral, FloatingLiteral,
CXXBoolLiteralExpr, CXXNullPtrLiteralExpr>(E);
}

static bool isUnaryExprOfLiteral(const Expr *E) {
if (const auto *UnOp = dyn_cast<UnaryOperator>(E))
return isLiteral(UnOp->getSubExpr());
return false;
}

static bool shouldBeDefaultMemberInitializer(const Expr *Value) {
if (isLiteral(Value) || isUnaryExprOfLiteral(Value))
return true;

if (const auto *DRE = dyn_cast<DeclRefExpr>(Value))
return isa<EnumConstantDecl>(DRE->getDecl());

return false;
}

namespace {

AST_MATCHER_P(FieldDecl, indexNotLessThan, unsigned, Index) {
Expand Down Expand Up @@ -166,19 +145,7 @@ isAssignmentToMemberOf(const CXXRecordDecl *Rec, const Stmt *S,

PreferMemberInitializerCheck::PreferMemberInitializerCheck(
StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
IsUseDefaultMemberInitEnabled(
Context->isCheckEnabled("modernize-use-default-member-init")),
UseAssignment(
Options.get("UseAssignment",
OptionsView("modernize-use-default-member-init",
Context->getOptions().CheckOptions, Context)
.get("UseAssignment", false))) {}

void PreferMemberInitializerCheck::storeOptions(
ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "UseAssignment", UseAssignment);
}
: ClangTidyCheck(Name, Context) {}

void PreferMemberInitializerCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(cxxConstructorDecl(hasBody(compoundStmt()),
Expand Down Expand Up @@ -230,139 +197,99 @@ void PreferMemberInitializerCheck::check(
updateAssignmentLevel(Field, InitValue, Ctor, AssignedFields);
if (!canAdvanceAssignment(AssignedFields[Field]))
continue;
const bool IsInDefaultMemberInitializer =
IsUseDefaultMemberInitEnabled && getLangOpts().CPlusPlus11 &&
Ctor->isDefaultConstructor() &&
(getLangOpts().CPlusPlus20 || !Field->isBitField()) &&
!Field->hasInClassInitializer() &&
(!isa<RecordDecl>(Class->getDeclContext()) ||
!cast<RecordDecl>(Class->getDeclContext())->isUnion()) &&
shouldBeDefaultMemberInitializer(InitValue);
if (IsInDefaultMemberInitializer) {
bool InvalidFix = false;
SourceLocation FieldEnd =
Lexer::getLocForEndOfToken(Field->getSourceRange().getEnd(), 0,
*Result.SourceManager, getLangOpts());
InvalidFix |= FieldEnd.isInvalid() || FieldEnd.isMacroID();
SourceLocation SemiColonEnd;
if (auto NextToken = Lexer::findNextToken(
S->getEndLoc(), *Result.SourceManager, getLangOpts()))
SemiColonEnd = NextToken->getEndLoc();
else
InvalidFix = true;
auto Diag =
diag(S->getBeginLoc(), "%0 should be initialized in an in-class"
" default member initializer")
<< Field;
if (InvalidFix)
continue;
CharSourceRange StmtRange =
CharSourceRange::getCharRange(S->getBeginLoc(), SemiColonEnd);

SmallString<128> Insertion(
{UseAssignment ? " = " : "{",
Lexer::getSourceText(Result.SourceManager->getExpansionRange(
InitValue->getSourceRange()),
*Result.SourceManager, getLangOpts()),
UseAssignment ? "" : "}"});

Diag << FixItHint::CreateInsertion(FieldEnd, Insertion)
<< FixItHint::CreateRemoval(StmtRange);

} else {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diff is very unfortunate, but essentially there's no changes to the code inside this "else" block. It's just unindented 2 spaces. The main change is the removal of the "if" block.

StringRef InsertPrefix = "";
bool HasInitAlready = false;
SourceLocation InsertPos;
SourceRange ReplaceRange;
bool AddComma = false;
bool InvalidFix = false;
unsigned Index = Field->getFieldIndex();
const CXXCtorInitializer *LastInListInit = nullptr;
for (const CXXCtorInitializer *Init : Ctor->inits()) {
if (!Init->isWritten() || Init->isInClassMemberInitializer())
continue;
if (Init->getMember() == Field) {
HasInitAlready = true;
if (isa<ImplicitValueInitExpr>(Init->getInit()))
InsertPos = Init->getRParenLoc();
else {
ReplaceRange = Init->getInit()->getSourceRange();
}
break;
}
if (Init->isMemberInitializer() &&
Index < Init->getMember()->getFieldIndex()) {
InsertPos = Init->getSourceLocation();
// There are initializers after the one we are inserting, so add a
// comma after this insertion in order to not break anything.
AddComma = true;
break;
StringRef InsertPrefix = "";
bool HasInitAlready = false;
SourceLocation InsertPos;
SourceRange ReplaceRange;
bool AddComma = false;
bool InvalidFix = false;
unsigned Index = Field->getFieldIndex();
const CXXCtorInitializer *LastInListInit = nullptr;
for (const CXXCtorInitializer *Init : Ctor->inits()) {
if (!Init->isWritten() || Init->isInClassMemberInitializer())
continue;
if (Init->getMember() == Field) {
HasInitAlready = true;
if (isa<ImplicitValueInitExpr>(Init->getInit()))
InsertPos = Init->getRParenLoc();
else {
ReplaceRange = Init->getInit()->getSourceRange();
}
LastInListInit = Init;
break;
}
if (HasInitAlready) {
if (InsertPos.isValid())
InvalidFix |= InsertPos.isMacroID();
else
InvalidFix |= ReplaceRange.getBegin().isMacroID() ||
ReplaceRange.getEnd().isMacroID();
} else {
if (InsertPos.isInvalid()) {
if (LastInListInit) {
InsertPos = Lexer::getLocForEndOfToken(
LastInListInit->getRParenLoc(), 0, *Result.SourceManager,
getLangOpts());
// Inserting after the last constructor initializer, so we need a
// comma.
InsertPrefix = ", ";
} else {
InsertPos = Lexer::getLocForEndOfToken(
Ctor->getTypeSourceInfo()
->getTypeLoc()
.getAs<clang::FunctionTypeLoc>()
.getLocalRangeEnd(),
0, *Result.SourceManager, getLangOpts());

// If this is first time in the loop, there are no initializers so
// `:` declares member initialization list. If this is a
// subsequent pass then we have already inserted a `:` so continue
// with a comma.
InsertPrefix = FirstToCtorInits ? " : " : ", ";
}
}
if (Init->isMemberInitializer() &&
Index < Init->getMember()->getFieldIndex()) {
InsertPos = Init->getSourceLocation();
// There are initializers after the one we are inserting, so add a
// comma after this insertion in order to not break anything.
AddComma = true;
break;
}
LastInListInit = Init;
}
if (HasInitAlready) {
if (InsertPos.isValid())
InvalidFix |= InsertPos.isMacroID();
else
InvalidFix |= ReplaceRange.getBegin().isMacroID() ||
ReplaceRange.getEnd().isMacroID();
} else {
if (InsertPos.isInvalid()) {
if (LastInListInit) {
InsertPos =
Lexer::getLocForEndOfToken(LastInListInit->getRParenLoc(), 0,
*Result.SourceManager, getLangOpts());
// Inserting after the last constructor initializer, so we need a
// comma.
InsertPrefix = ", ";
} else {
InsertPos = Lexer::getLocForEndOfToken(
Ctor->getTypeSourceInfo()
->getTypeLoc()
.getAs<clang::FunctionTypeLoc>()
.getLocalRangeEnd(),
0, *Result.SourceManager, getLangOpts());

// If this is first time in the loop, there are no initializers so
// `:` declares member initialization list. If this is a
// subsequent pass then we have already inserted a `:` so continue
// with a comma.
InsertPrefix = FirstToCtorInits ? " : " : ", ";
}
}
InvalidFix |= InsertPos.isMacroID();
}

SourceLocation SemiColonEnd;
if (auto NextToken = Lexer::findNextToken(
S->getEndLoc(), *Result.SourceManager, getLangOpts()))
SemiColonEnd = NextToken->getEndLoc();
SourceLocation SemiColonEnd;
if (auto NextToken = Lexer::findNextToken(
S->getEndLoc(), *Result.SourceManager, getLangOpts()))
SemiColonEnd = NextToken->getEndLoc();
else
InvalidFix = true;

auto Diag = diag(S->getBeginLoc(), "%0 should be initialized in a member"
" initializer of the constructor")
<< Field;
if (InvalidFix)
continue;
StringRef NewInit = Lexer::getSourceText(
Result.SourceManager->getExpansionRange(InitValue->getSourceRange()),
*Result.SourceManager, getLangOpts());
if (HasInitAlready) {
if (InsertPos.isValid())
Diag << FixItHint::CreateInsertion(InsertPos, NewInit);
else
InvalidFix = true;

auto Diag = diag(S->getBeginLoc(), "%0 should be initialized in a member"
" initializer of the constructor")
<< Field;
if (InvalidFix)
continue;
StringRef NewInit = Lexer::getSourceText(
Result.SourceManager->getExpansionRange(InitValue->getSourceRange()),
*Result.SourceManager, getLangOpts());
if (HasInitAlready) {
if (InsertPos.isValid())
Diag << FixItHint::CreateInsertion(InsertPos, NewInit);
else
Diag << FixItHint::CreateReplacement(ReplaceRange, NewInit);
} else {
SmallString<128> Insertion({InsertPrefix, Field->getName(), "(",
NewInit, AddComma ? "), " : ")"});
Diag << FixItHint::CreateInsertion(InsertPos, Insertion,
FirstToCtorInits);
FirstToCtorInits = areDiagsSelfContained();
}
Diag << FixItHint::CreateRemoval(
CharSourceRange::getCharRange(S->getBeginLoc(), SemiColonEnd));
Diag << FixItHint::CreateReplacement(ReplaceRange, NewInit);
} else {
SmallString<128> Insertion({InsertPrefix, Field->getName(), "(", NewInit,
AddComma ? "), " : ")"});
Diag << FixItHint::CreateInsertion(InsertPos, Insertion,
FirstToCtorInits);
FirstToCtorInits = areDiagsSelfContained();
}
Diag << FixItHint::CreateRemoval(
CharSourceRange::getCharRange(S->getBeginLoc(), SemiColonEnd));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,8 @@ class PreferMemberInitializerCheck : public ClangTidyCheck {
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
}
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;

const bool IsUseDefaultMemberInitEnabled;
const bool UseAssignment;
};

} // namespace clang::tidy::cppcoreguidelines
Expand Down
8 changes: 8 additions & 0 deletions clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ New check aliases
Changes in existing checks
^^^^^^^^^^^^^^^^^^^^^^^^^^

- Removed enforcement of rule `C.48
<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c48-prefer-in-class-initializers-to-member-initializers-in-constructors-for-constant-initializers>`_
from :doc:`cppcoreguidelines-prefer-member-initializer
<clang-tidy/checks/cppcoreguidelines/prefer-member-initializer>`.
This functionality was deprecated since :program:`clang-tidy` 17, where a new
check was added to cover only this rule: :doc:`cppcoreguidelines-use-default-member-init
<clang-tidy/checks/cppcoreguidelines/use-default-member-init>`.

Removed checks
^^^^^^^^^^^^^^

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,11 @@ This check implements `C.49
<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c49-prefer-initialization-to-assignment-in-constructors>`_
from the C++ Core Guidelines.

If the language version is `C++ 11` or above, the constructor is the default
constructor of the class, the field is not a bitfield (only in case of earlier
language version than `C++ 20`), furthermore the assigned value is a literal,
negated literal or ``enum`` constant then the preferred place of the
initialization is at the class member declaration.

This latter rule is `C.48
Please note, that this check does not enforce rule `C.48
<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c48-prefer-in-class-initializers-to-member-initializers-in-constructors-for-constant-initializers>`_
from the C++ Core Guidelines.

Please note, that this check does not enforce this latter rule for
initializations already implemented as member initializers. For that purpose
from the C++ Core Guidelines. For that purpose
see check :doc:`modernize-use-default-member-init <../modernize/use-default-member-init>`.

.. note::

Enforcement of rule C.48 in this check is deprecated, to be removed in
:program:`clang-tidy` version 19 (only C.49 will be enforced by this check then).
Please use :doc:`cppcoreguidelines-use-default-member-init <../cppcoreguidelines/use-default-member-init>`
to enforce rule C.48.

Example 1
---------

Expand All @@ -51,16 +35,16 @@ Example 1
}
};

Here ``n`` can be initialized using a default member initializer, unlike
Here ``n`` can be initialized in the constructor initializer list, unlike
``m``, as ``m``'s initialization follows a control statement (``if``):

.. code-block:: c++

class C {
int n{1};
int n;
int m;
public:
C() {
C(): n(1) {
if (dice())
return;
m = 1;
Expand All @@ -84,7 +68,7 @@ Example 2
}
};

Here ``n`` can be initialized in the constructor initialization list, unlike
Here ``n`` can be initialized in the constructor initializer list, unlike
``m``, as ``m``'s initialization follows a control statement (``if``):

.. code-block:: c++
Expand All @@ -94,29 +78,3 @@ Here ``n`` can be initialized in the constructor initialization list, unlike
return;
m = mm;
}

.. option:: UseAssignment

Note: this option is deprecated, to be removed in :program:`clang-tidy`
version 19. Please use the `UseAssignment` option from
:doc:`cppcoreguidelines-use-default-member-init <../cppcoreguidelines/use-default-member-init>`
instead.

If this option is set to `true` (by default `UseAssignment` from
:doc:`modernize-use-default-member-init
<../modernize/use-default-member-init>` will be used),
the check will initialize members with an assignment.
In this case the fix of the first example looks like this:

.. code-block:: c++

class C {
int n = 1;
int m;
public:
C() {
if (dice())
return;
m = 1;
}
};
Loading
Loading