Skip to content

Commit 298712b

Browse files
authored
Merge branch 'main' into 84749
2 parents c2f47d6 + 97fb91e commit 298712b

File tree

1,148 files changed

+26350
-10789
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,148 files changed

+26350
-10789
lines changed

.ci/monolithic-linux.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@ cmake -S ${MONOREPO_ROOT}/llvm -B ${BUILD_DIR} \
5454

5555
echo "--- ninja"
5656
# Targets are not escaped as they are passed as separate arguments.
57-
ninja -C "${BUILD_DIR}" ${targets}
57+
ninja -C "${BUILD_DIR}" -k 0 ${targets}

.ci/monolithic-windows.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,4 @@ cmake -S ${MONOREPO_ROOT}/llvm -B ${BUILD_DIR} \
6262

6363
echo "--- ninja"
6464
# Targets are not escaped as they are passed as separate arguments.
65-
ninja -C "${BUILD_DIR}" ${targets}
65+
ninja -C "${BUILD_DIR}" -k 0 ${targets}

.github/workflows/issue-release-workflow.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,5 @@ jobs:
6565
release-workflow \
6666
--branch-repo-token ${{ secrets.RELEASE_WORKFLOW_PUSH_SECRET }} \
6767
--issue-number ${{ github.event.issue.number }} \
68-
--requested-by ${{ github.event.issue.user.login }} \
68+
--requested-by ${{ (github.event.action == 'opened' && github.event.issue.user.login) || github.event.comment.user.login }} \
6969
auto

.github/workflows/release-binaries.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ jobs:
7171
# | X.Y.Z | -final
7272
run: |
7373
tag="${{ github.ref_name }}"
74-
trimmed=$(echo ${{ inputs.tag }} | xargs)
75-
[[ "$trimmed" != "" ]] && tag="$trimmed"
74+
trimmed=$(echo ${{ inputs.release-version }} | xargs)
75+
[[ "$trimmed" != "" ]] && tag="llvmorg-$trimmed"
7676
if [ "$tag" = "main" ]; then
7777
# If tag is main, then we've been triggered by a scheduled so pass so
7878
# use the head commit as the tag.

bolt/lib/Core/DebugNames.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,13 @@ void DWARF5AcceleratorTable::finalize() {
345345
std::optional<DWARF5AccelTable::UnitIndexAndEncoding>
346346
DWARF5AcceleratorTable::getIndexForEntry(
347347
const BOLTDWARF5AccelTableData &Value) const {
348+
// The foreign TU list immediately follows the local TU list and they both
349+
// use the same index, so that if there are N local TU entries, the index for
350+
// the first foreign TU is N.
348351
if (Value.isTU())
349-
return {{Value.getUnitID(), {dwarf::DW_IDX_type_unit, TUIndexForm}}};
352+
return {{(Value.getSecondUnitID() ? (unsigned)LocalTUList.size() : 0) +
353+
Value.getUnitID(),
354+
{dwarf::DW_IDX_type_unit, TUIndexForm}}};
350355
if (CUList.size() > 1)
351356
return {{Value.getUnitID(), {dwarf::DW_IDX_compile_unit, CUIndexForm}}};
352357
return std::nullopt;

bolt/test/X86/Inputs/dwarf5-debug-names-ftu-ltu-mix-helper.s

Lines changed: 314 additions & 0 deletions
Large diffs are not rendered by default.

bolt/test/X86/Inputs/dwarf5-debug-names-ftu-ltu-mix-helper1.s

Lines changed: 315 additions & 0 deletions
Large diffs are not rendered by default.

bolt/test/X86/Inputs/dwarf5-df-debug-names-ftu-ltu-mix-main.s

Lines changed: 505 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
; RUN: rm -rf %t
2+
; RUN: mkdir %t
3+
; RUN: cd %t
4+
; RUN: llvm-mc -dwarf-version=5 -filetype=obj -triple x86_64-unknown-linux %p/Inputs/dwarf5-df-debug-names-ftu-ltu-mix-main.s \
5+
; RUN: -split-dwarf-file=main.dwo -o main.o
6+
; RUN: llvm-mc -dwarf-version=5 -filetype=obj -triple x86_64-unknown-linux %p/Inputs/dwarf5-debug-names-ftu-ltu-mix-helper.s -o helper.o
7+
; RUN: llvm-mc -dwarf-version=5 -filetype=obj -triple x86_64-unknown-linux %p/Inputs/dwarf5-debug-names-ftu-ltu-mix-helper1.s -o helper1.o
8+
; RUN: %clang %cflags -gdwarf-5 -gsplit-dwarf=split main.o helper.o helper1.o -o main.exe -fno-pic -no-pie
9+
; RUN: llvm-bolt main.exe -o main.exe.bolt --update-debug-sections --create-debug-names-section=true
10+
; RUN: llvm-dwarfdump --debug-names main.exe.bolt | FileCheck -check-prefix=BOLT %s
11+
12+
;; Tests BOLT correctly sets foreign TU Index when there are local TUs.
13+
14+
; BOLT: Compilation Unit offsets [
15+
; BOLT-NEXT: CU[0]: {{.+}}
16+
; BOLT-NEXT: CU[1]: {{.+}}
17+
; BOLT-NEXT: CU[2]: {{.+}}
18+
; BOLT-NEXT: ]
19+
; BOLT-NEXT: Local Type Unit offsets [
20+
; BOLT-NEXT: LocalTU[0]: {{.+}}
21+
; BOLT-NEXT: LocalTU[1]: {{.+}}
22+
; BOLT-NEXT: ]
23+
; BOLT-NEXT: Foreign Type Unit signatures [
24+
; BOLT-NEXT: ForeignTU[0]: 0x889c84450dac881f
25+
; BOLT-NEXT: ]
26+
; BOLT: Name 3 {
27+
; BOLT-NEXT: Hash: 0x6A05C500
28+
; BOLT-NEXT: String: {{.+}} "globalMono1"
29+
; BOLT-NEXT: Entry @ {{.+}} {
30+
; BOLT-NEXT: Abbrev: 0x5
31+
; BOLT-NEXT: Tag: DW_TAG_variable
32+
; BOLT-NEXT: DW_IDX_compile_unit: 0x02
33+
; BOLT-NEXT: DW_IDX_die_offset: 0x0000001e
34+
; BOLT-NEXT: }
35+
; BOLT-NEXT: }
36+
; BOLT: Name 6 {
37+
; BOLT-NEXT: Hash: 0xF283AF92
38+
; BOLT-NEXT: String: {{.+}} "ASplit"
39+
; BOLT-NEXT: Entry @ {{.+}} {
40+
; BOLT-NEXT: Abbrev: 0x7
41+
; BOLT-NEXT: Tag: DW_TAG_structure_type
42+
; BOLT-NEXT: DW_IDX_type_unit: 0x02
43+
; BOLT-NEXT: DW_IDX_compile_unit: 0x00
44+
; BOLT-NEXT: DW_IDX_die_offset: 0x00000021
45+
; BOLT-NEXT: }
46+
; BOLT-NEXT: }
47+
; BOLT: Name 7 {
48+
; BOLT-NEXT: Hash: 0xF17F51F
49+
; BOLT-NEXT: String: {{.+}} "AMono"
50+
; BOLT-NEXT: Entry @ {{.+}} {
51+
; BOLT-NEXT: Abbrev: 0x4
52+
; BOLT-NEXT: Tag: DW_TAG_structure_type
53+
; BOLT-NEXT: DW_IDX_type_unit: 0x00
54+
; BOLT-NEXT: DW_IDX_die_offset: 0x00000023
55+
; BOLT-NEXT: }
56+
; BOLT-NEXT: }

clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include "../utils/OptionsUtils.h"
1212
#include "clang/AST/ASTContext.h"
1313
#include "clang/ASTMatchers/ASTMatchFinder.h"
14+
#include "clang/ASTMatchers/ASTMatchers.h"
15+
#include "clang/Basic/OperatorKinds.h"
1416

1517
using namespace clang::ast_matchers;
1618
using namespace clang::ast_matchers::internal;
@@ -28,6 +30,11 @@ AST_MATCHER_P(FunctionDecl, isInstantiatedFrom, Matcher<FunctionDecl>,
2830
return InnerMatcher.matches(InstantiatedFrom ? *InstantiatedFrom : Node,
2931
Finder, Builder);
3032
}
33+
34+
AST_MATCHER_P(CXXMethodDecl, isOperatorOverloading,
35+
llvm::SmallVector<OverloadedOperatorKind>, Kinds) {
36+
return llvm::is_contained(Kinds, Node.getOverloadedOperator());
37+
}
3138
} // namespace
3239

3340
UnusedReturnValueCheck::UnusedReturnValueCheck(llvm::StringRef Name,
@@ -157,16 +164,22 @@ void UnusedReturnValueCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
157164
}
158165

159166
void UnusedReturnValueCheck::registerMatchers(MatchFinder *Finder) {
160-
auto MatchedDirectCallExpr =
161-
expr(callExpr(callee(functionDecl(
162-
// Don't match void overloads of checked functions.
163-
unless(returns(voidType())),
164-
anyOf(isInstantiatedFrom(matchers::matchesAnyListedName(
165-
CheckedFunctions)),
166-
returns(hasCanonicalType(hasDeclaration(
167-
namedDecl(matchers::matchesAnyListedName(
168-
CheckedReturnTypes)))))))))
169-
.bind("match"));
167+
auto MatchedDirectCallExpr = expr(
168+
callExpr(
169+
callee(functionDecl(
170+
// Don't match void overloads of checked functions.
171+
unless(returns(voidType())),
172+
// Don't match copy or move assignment operator.
173+
unless(cxxMethodDecl(isOperatorOverloading(
174+
{OO_Equal, OO_PlusEqual, OO_MinusEqual, OO_StarEqual,
175+
OO_SlashEqual, OO_PercentEqual, OO_CaretEqual, OO_AmpEqual,
176+
OO_PipeEqual, OO_LessLessEqual, OO_GreaterGreaterEqual}))),
177+
anyOf(
178+
isInstantiatedFrom(
179+
matchers::matchesAnyListedName(CheckedFunctions)),
180+
returns(hasCanonicalType(hasDeclaration(namedDecl(
181+
matchers::matchesAnyListedName(CheckedReturnTypes)))))))))
182+
.bind("match"));
170183

171184
auto CheckCastToVoid =
172185
AllowCastToVoid ? castExpr(unless(hasCastKind(CK_ToVoid))) : castExpr();

clang-tools-extra/clangd/ClangdServer.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ void ClangdServer::formatFile(PathRef File, std::optional<Range> Rng,
523523
auto Action = [File = File.str(), Code = std::move(*Code),
524524
Ranges = std::vector<tooling::Range>{RequestedRange},
525525
CB = std::move(CB), this]() mutable {
526-
format::FormatStyle Style = getFormatStyleForFile(File, Code, TFS);
526+
format::FormatStyle Style = getFormatStyleForFile(File, Code, TFS, true);
527527
tooling::Replacements IncludeReplaces =
528528
format::sortIncludes(Style, Code, Ranges, File);
529529
auto Changed = tooling::applyAllReplacements(Code, IncludeReplaces);
@@ -551,7 +551,7 @@ void ClangdServer::formatOnType(PathRef File, Position Pos,
551551
auto Action = [File = File.str(), Code = std::move(*Code),
552552
TriggerText = TriggerText.str(), CursorPos = *CursorPos,
553553
CB = std::move(CB), this]() mutable {
554-
auto Style = getFormatStyleForFile(File, Code, TFS);
554+
auto Style = getFormatStyleForFile(File, Code, TFS, false);
555555
std::vector<TextEdit> Result;
556556
for (const tooling::Replacement &R :
557557
formatIncremental(Code, CursorPos, TriggerText, Style))
@@ -605,7 +605,7 @@ void ClangdServer::rename(PathRef File, Position Pos, llvm::StringRef NewName,
605605

606606
if (Opts.WantFormat) {
607607
auto Style = getFormatStyleForFile(File, InpAST->Inputs.Contents,
608-
*InpAST->Inputs.TFS);
608+
*InpAST->Inputs.TFS, false);
609609
llvm::Error Err = llvm::Error::success();
610610
for (auto &E : R->GlobalChanges)
611611
Err =
@@ -762,7 +762,7 @@ void ClangdServer::applyTweak(PathRef File, Range Sel, StringRef TweakID,
762762
for (auto &It : (*Effect)->ApplyEdits) {
763763
Edit &E = It.second;
764764
format::FormatStyle Style =
765-
getFormatStyleForFile(File, E.InitialCode, TFS);
765+
getFormatStyleForFile(File, E.InitialCode, TFS, false);
766766
if (llvm::Error Err = reformatEdit(E, Style))
767767
elog("Failed to format {0}: {1}", It.first(), std::move(Err));
768768
}
@@ -825,7 +825,7 @@ void ClangdServer::findHover(PathRef File, Position Pos,
825825
if (!InpAST)
826826
return CB(InpAST.takeError());
827827
format::FormatStyle Style = getFormatStyleForFile(
828-
File, InpAST->Inputs.Contents, *InpAST->Inputs.TFS);
828+
File, InpAST->Inputs.Contents, *InpAST->Inputs.TFS, false);
829829
CB(clangd::getHover(InpAST->AST, Pos, std::move(Style), Index));
830830
};
831831

clang-tools-extra/clangd/CodeComplete.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,7 +1628,7 @@ class CodeCompleteFlow {
16281628
IsUsingDeclaration = Recorder->CCContext.isUsingDeclaration();
16291629
auto Style = getFormatStyleForFile(SemaCCInput.FileName,
16301630
SemaCCInput.ParseInput.Contents,
1631-
*SemaCCInput.ParseInput.TFS);
1631+
*SemaCCInput.ParseInput.TFS, false);
16321632
const auto NextToken = findTokenAfterCompletionPoint(
16331633
Recorder->CCSema->getPreprocessor().getCodeCompletionLoc(),
16341634
Recorder->CCSema->getSourceManager(), Recorder->CCSema->LangOpts);
@@ -1719,7 +1719,7 @@ class CodeCompleteFlow {
17191719
ProxSources[FileName].Cost = 0;
17201720
FileProximity.emplace(ProxSources);
17211721

1722-
auto Style = getFormatStyleForFile(FileName, Content, TFS);
1722+
auto Style = getFormatStyleForFile(FileName, Content, TFS, false);
17231723
// This will only insert verbatim headers.
17241724
Inserter.emplace(FileName, Content, Style,
17251725
/*BuildDir=*/"", /*HeaderSearchInfo=*/nullptr);

clang-tools-extra/clangd/IncludeCleaner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ std::vector<Diag> generateMissingIncludeDiagnostics(
116116
const SourceManager &SM = AST.getSourceManager();
117117
const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID());
118118

119-
auto FileStyle = getFormatStyleForFile(AST.tuPath(), Code, TFS);
119+
auto FileStyle = getFormatStyleForFile(AST.tuPath(), Code, TFS, false);
120120

121121
tooling::HeaderIncludes HeaderIncludes(AST.tuPath(), Code,
122122
FileStyle.IncludeStyle);

clang-tools-extra/clangd/ParsedAST.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ ParsedAST::build(llvm::StringRef Filename, const ParseInputs &Inputs,
626626
// (e.g. incomplete type) and attach include insertion fixes to diagnostics.
627627
if (Inputs.Index && !BuildDir.getError()) {
628628
auto Style =
629-
getFormatStyleForFile(Filename, Inputs.Contents, *Inputs.TFS);
629+
getFormatStyleForFile(Filename, Inputs.Contents, *Inputs.TFS, false);
630630
auto Inserter = std::make_shared<IncludeInserter>(
631631
Filename, Inputs.Contents, Style, BuildDir.get(),
632632
&Clang->getPreprocessor().getHeaderSearchInfo());

clang-tools-extra/clangd/Protocol.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1412,7 +1412,7 @@ bool fromJSON(const llvm::json::Value &Params, ReferenceParams &R,
14121412
}
14131413

14141414
llvm::json::Value toJSON(SymbolTag Tag) {
1415-
return llvm::json::Value{static_cast<int>(Tag)};
1415+
return llvm::json::Value(static_cast<int>(Tag));
14161416
}
14171417

14181418
llvm::json::Value toJSON(const CallHierarchyItem &I) {

clang-tools-extra/clangd/SourceCode.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,21 @@ std::optional<FileDigest> digestFile(const SourceManager &SM, FileID FID) {
582582

583583
format::FormatStyle getFormatStyleForFile(llvm::StringRef File,
584584
llvm::StringRef Content,
585-
const ThreadsafeFS &TFS) {
585+
const ThreadsafeFS &TFS,
586+
bool FormatFile) {
587+
// Unless we're formatting a substantial amount of code (the entire file
588+
// or an arbitrarily large range), skip libFormat's heuristic check for
589+
// .h files that tries to determine whether the file contains objective-c
590+
// code. (This is accomplished by passing empty code contents to getStyle().
591+
// The heuristic is the only thing that looks at the contents.)
592+
// This is a workaround for PR60151, a known issue in libFormat where this
593+
// heuristic can OOM on large files. If we *are* formatting the entire file,
594+
// there's no point in doing this because the actual format::reformat() call
595+
// will run into the same OOM; we'd just be risking inconsistencies between
596+
// clangd and clang-format on smaller .h files where they disagree on what
597+
// language is detected.
598+
if (!FormatFile)
599+
Content = {};
586600
auto Style = format::getStyle(format::DefaultFormatStyle, File,
587601
format::DefaultFallbackStyle, Content,
588602
TFS.view(/*CWD=*/std::nullopt).get());

clang-tools-extra/clangd/SourceCode.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,13 @@ std::optional<std::string> getCanonicalPath(const FileEntryRef F,
171171
/// FIXME: should we be caching the .clang-format file search?
172172
/// This uses format::DefaultFormatStyle and format::DefaultFallbackStyle,
173173
/// though the latter may have been overridden in main()!
174+
/// \p FormatFile indicates whether the returned FormatStyle is used
175+
/// to format the entire main file (or a range selected by the user
176+
/// which can be arbitrarily long).
174177
format::FormatStyle getFormatStyleForFile(llvm::StringRef File,
175178
llvm::StringRef Content,
176-
const ThreadsafeFS &TFS);
179+
const ThreadsafeFS &TFS,
180+
bool FormatFile);
177181

178182
/// Cleanup and format the given replacements.
179183
llvm::Expected<tooling::Replacements>

clang-tools-extra/clangd/tool/Check.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ class Checker {
226226

227227
// FIXME: Check that resource-dir/built-in-headers exist?
228228

229-
Style = getFormatStyleForFile(File, Inputs.Contents, TFS);
229+
Style = getFormatStyleForFile(File, Inputs.Contents, TFS, false);
230230

231231
return true;
232232
}

clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ TEST(DiagnosticTest, RespectsDiagnosticConfig) {
544544
Diag(Main.range("ret"),
545545
"void function 'x' should not return a value")));
546546
Config Cfg;
547-
Cfg.Diagnostics.Suppress.insert("return-type");
547+
Cfg.Diagnostics.Suppress.insert("return-mismatch");
548548
WithContextValue WithCfg(Config::Key, std::move(Cfg));
549549
EXPECT_THAT(TU.build().getDiagnostics(),
550550
ElementsAre(Diag(Main.range(),

clang-tools-extra/clangd/unittests/SourceCodeTests.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,6 +1090,44 @@ TEST(ApplyEditsTest, EndLineOutOfRange) {
10901090
FailedWithMessage("Line value is out of range (100)"));
10911091
}
10921092

1093+
TEST(FormatStyleForFile, LanguageGuessingHeuristic) {
1094+
StringRef ObjCContent = "@interface Foo\n@end\n";
1095+
StringRef CppContent = "class Foo {};\n";
1096+
using LK = format::FormatStyle::LanguageKind;
1097+
struct TestCase {
1098+
llvm::StringRef Filename;
1099+
llvm::StringRef Contents;
1100+
bool FormatFile;
1101+
LK ExpectedLanguage;
1102+
} TestCases[] = {
1103+
// If the file extension identifies the file as ObjC, the guessed
1104+
// language should be ObjC regardless of content or FormatFile flag.
1105+
{"foo.mm", ObjCContent, true, LK::LK_ObjC},
1106+
{"foo.mm", ObjCContent, false, LK::LK_ObjC},
1107+
{"foo.mm", CppContent, true, LK::LK_ObjC},
1108+
{"foo.mm", CppContent, false, LK::LK_ObjC},
1109+
1110+
// If the file extension is ambiguous like .h, FormatFile=true should
1111+
// result in using libFormat's heuristic to guess the language based
1112+
// on the file contents.
1113+
{"foo.h", ObjCContent, true, LK::LK_ObjC},
1114+
{"foo.h", CppContent, true, LK::LK_Cpp},
1115+
1116+
// With FomatFile=false, the language guessing heuristic should be
1117+
// bypassed
1118+
{"foo.h", ObjCContent, false, LK::LK_Cpp},
1119+
{"foo.h", CppContent, false, LK::LK_Cpp},
1120+
};
1121+
1122+
MockFS FS;
1123+
for (const auto &[Filename, Contents, FormatFile, ExpectedLanguage] :
1124+
TestCases) {
1125+
EXPECT_EQ(
1126+
getFormatStyleForFile(Filename, Contents, FS, FormatFile).Language,
1127+
ExpectedLanguage);
1128+
}
1129+
}
1130+
10931131
} // namespace
10941132
} // namespace clangd
10951133
} // namespace clang

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ Changes in existing checks
152152

153153
- Improved :doc:`bugprone-unused-return-value
154154
<clang-tidy/checks/bugprone/unused-return-value>` check by updating the
155-
parameter `CheckedFunctions` to support regexp and avoiding false postive for
155+
parameter `CheckedFunctions` to support regexp, avoiding false positive for
156156
function with the same prefix as the default argument, e.g. ``std::unique_ptr``
157-
and ``std::unique``.
157+
and ``std::unique``, avoiding false positive for assignment operator overloading.
158158

159159
- Improved :doc:`bugprone-use-after-move
160160
<clang-tidy/checks/bugprone/use-after-move>` check to also handle

clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ bugprone-unused-return-value
55

66
Warns on unused function return values. The checked functions can be configured.
77

8+
Operator overloading with assignment semantics are ignored.
9+
810
Options
911
-------
1012

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// RUN: %check_clang_tidy %s bugprone-unused-return-value %t \
2+
// RUN: -config='{CheckOptions: \
3+
// RUN: {bugprone-unused-return-value.CheckedFunctions: "::*"}}' \
4+
// RUN: --
5+
6+
struct S {
7+
S(){};
8+
S(S const &);
9+
S(S &&);
10+
S &operator=(S const &);
11+
S &operator=(S &&);
12+
S &operator+=(S);
13+
};
14+
15+
S returnValue();
16+
S const &returnRef();
17+
18+
void bar() {
19+
returnValue();
20+
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should not be disregarded; neglecting it may lead to errors
21+
22+
S a{};
23+
a = returnValue();
24+
a.operator=(returnValue());
25+
26+
a = returnRef();
27+
a.operator=(returnRef());
28+
29+
a += returnRef();
30+
}

0 commit comments

Comments
 (0)