Skip to content

Commit 3219783

Browse files
committed
[clang][clang-tools-extra] LLVM_NODISCARD => [[nodiscard]]. NFC
1 parent d3580c2 commit 3219783

File tree

25 files changed

+227
-244
lines changed

25 files changed

+227
-244
lines changed

clang-tools-extra/clang-tidy/ClangTidyOptions.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ struct ClangTidyOptions {
6363
/// Creates a new \c ClangTidyOptions instance combined from all fields
6464
/// of this instance overridden by the fields of \p Other that have a value.
6565
/// \p Order specifies precedence of \p Other option.
66-
LLVM_NODISCARD ClangTidyOptions merge(const ClangTidyOptions &Other,
67-
unsigned Order) const;
66+
[[nodiscard]] ClangTidyOptions merge(const ClangTidyOptions &Other,
67+
unsigned Order) const;
6868

6969
/// Checks filter.
7070
llvm::Optional<std::string> Checks;

clang-tools-extra/clangd/ClangdServer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@ llvm::StringMap<TUScheduler::FileStats> ClangdServer::fileStats() const {
10001000
return WorkScheduler->fileStats();
10011001
}
10021002

1003-
LLVM_NODISCARD bool
1003+
[[nodiscard]] bool
10041004
ClangdServer::blockUntilIdleForTest(llvm::Optional<double> TimeoutSeconds) {
10051005
// Order is important here: we don't want to block on A and then B,
10061006
// if B might schedule work on A.

clang-tools-extra/clangd/ClangdServer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ class ClangdServer {
390390
// Returns false if the timeout expires.
391391
// FIXME: various subcomponents each get the full timeout, so it's more of
392392
// an order of magnitude than a hard deadline.
393-
LLVM_NODISCARD bool
393+
[[nodiscard]] bool
394394
blockUntilIdleForTest(llvm::Optional<double> TimeoutSeconds = 10);
395395

396396
/// Builds a nested representation of memory used by components.

clang-tools-extra/clangd/index/Background.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class BackgroundQueue {
110110
// Disables thread priority lowering to ensure progress on loaded systems.
111111
// Only affects tasks that run after the call.
112112
static void preventThreadStarvationInTests();
113-
LLVM_NODISCARD bool
113+
[[nodiscard]] bool
114114
blockUntilIdleForTest(llvm::Optional<double> TimeoutSeconds);
115115

116116
private:
@@ -172,7 +172,7 @@ class BackgroundIndex : public SwapIndex {
172172
}
173173

174174
// Wait until the queue is empty, to allow deterministic testing.
175-
LLVM_NODISCARD bool
175+
[[nodiscard]] bool
176176
blockUntilIdleForTest(llvm::Optional<double> TimeoutSeconds = 10) {
177177
return Queue.blockUntilIdleForTest(TimeoutSeconds);
178178
}

clang-tools-extra/clangd/index/Serialization.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class Reader {
116116
// Read a varint (as consumeVar) and resize the container accordingly.
117117
// If the size is invalid, return false and mark an error.
118118
// (The caller should abort in this case).
119-
template <typename T> LLVM_NODISCARD bool consumeSize(T &Container) {
119+
template <typename T> [[nodiscard]] bool consumeSize(T &Container) {
120120
auto Size = consumeVar();
121121
// Conservatively assume each element is at least one byte.
122122
if (Size > (size_t)(End - Begin)) {

clang-tools-extra/clangd/support/Context.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ class Context {
184184
/// WithContext replaces Context::current() with a provided scope.
185185
/// When the WithContext is destroyed, the original scope is restored.
186186
/// For extending the current context with new value, prefer WithContextValue.
187-
class LLVM_NODISCARD WithContext {
187+
class [[nodiscard]] WithContext {
188188
public:
189189
WithContext(Context C) : Restore(Context::swapCurrent(std::move(C))) {}
190190
~WithContext() { Context::swapCurrent(std::move(Restore)); }
@@ -199,7 +199,7 @@ class LLVM_NODISCARD WithContext {
199199

200200
/// WithContextValue extends Context::current() with a single value.
201201
/// When the WithContextValue is destroyed, the original scope is restored.
202-
class LLVM_NODISCARD WithContextValue {
202+
class [[nodiscard]] WithContextValue {
203203
public:
204204
template <typename T>
205205
WithContextValue(const Key<T> &K, typename std::decay<T>::type V)

clang-tools-extra/clangd/support/Function.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ template <typename T> class Event {
3535

3636
// A subscription defines the scope of when a listener should receive events.
3737
// After destroying the subscription, no more events are received.
38-
class LLVM_NODISCARD Subscription {
38+
class [[nodiscard]] Subscription {
3939
Event *Parent;
4040
unsigned ListenerID;
4141

clang-tools-extra/clangd/support/Threading.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ void wait(std::unique_lock<std::mutex> &Lock, std::condition_variable &CV,
7676
Deadline D);
7777
/// Waits on a condition variable until F() is true or D expires.
7878
template <typename Func>
79-
LLVM_NODISCARD bool wait(std::unique_lock<std::mutex> &Lock,
80-
std::condition_variable &CV, Deadline D, Func F) {
79+
[[nodiscard]] bool wait(std::unique_lock<std::mutex> &Lock,
80+
std::condition_variable &CV, Deadline D, Func F) {
8181
while (!F()) {
8282
if (D.expired())
8383
return false;
@@ -93,7 +93,7 @@ class Notification {
9393
void notify();
9494
// Blocks until flag is set.
9595
void wait() const { (void)wait(Deadline::infinity()); }
96-
LLVM_NODISCARD bool wait(Deadline D) const;
96+
[[nodiscard]] bool wait(Deadline D) const;
9797

9898
private:
9999
bool Notified = false;
@@ -110,7 +110,7 @@ class AsyncTaskRunner {
110110
~AsyncTaskRunner();
111111

112112
void wait() const { (void)wait(Deadline::infinity()); }
113-
LLVM_NODISCARD bool wait(Deadline D) const;
113+
[[nodiscard]] bool wait(Deadline D) const;
114114
// The name is used for tracing and debugging (e.g. to name a spawned thread).
115115
void runAsync(const llvm::Twine &Name, llvm::unique_function<void()> Action);
116116

clang/include/clang/AST/ASTContext.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3202,11 +3202,11 @@ OPT_LIST(V)
32023202

32033203
#undef OPT_LIST
32043204

3205-
LLVM_NODISCARD ObjCEncOptions keepingOnly(ObjCEncOptions Mask) const {
3205+
[[nodiscard]] ObjCEncOptions keepingOnly(ObjCEncOptions Mask) const {
32063206
return Bits & Mask.Bits;
32073207
}
32083208

3209-
LLVM_NODISCARD ObjCEncOptions forComponentType() const {
3209+
[[nodiscard]] ObjCEncOptions forComponentType() const {
32103210
ObjCEncOptions Mask = ObjCEncOptions()
32113211
.setIsOutermostType()
32123212
.setIsStructField();

clang/include/clang/AST/ASTImporter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ class TypeSourceInfo;
304304
/// \param From Object to import.
305305
/// \return Error information (success or error).
306306
template <typename ImportT>
307-
LLVM_NODISCARD llvm::Error importInto(ImportT &To, const ImportT &From) {
307+
[[nodiscard]] llvm::Error importInto(ImportT &To, const ImportT &From) {
308308
auto ToOrErr = Import(From);
309309
if (ToOrErr)
310310
To = *ToOrErr;
@@ -482,7 +482,7 @@ class TypeSourceInfo;
482482

483483
/// Import the definition of the given declaration, including all of
484484
/// the declarations it contains.
485-
LLVM_NODISCARD llvm::Error ImportDefinition(Decl *From);
485+
[[nodiscard]] llvm::Error ImportDefinition(Decl *From);
486486

487487
/// Cope with a name conflict when importing a declaration into the
488488
/// given context.

clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ class SymbolGraphSerializer : public APISerializer {
164164
/// \param Component The component to push onto the path components stack.
165165
/// \return A PathComponentGuard responsible for removing the latest
166166
/// component from the stack on scope exit.
167-
LLVM_NODISCARD PathComponentGuard makePathComponentGuard(StringRef Component);
167+
[[nodiscard]] PathComponentGuard makePathComponentGuard(StringRef Component);
168168

169169
public:
170170
SymbolGraphSerializer(const APISet &API, StringRef ProductName,

clang/include/clang/StaticAnalyzer/Checkers/Taint.h

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,39 +27,39 @@ using TaintTagType = unsigned;
2727
static constexpr TaintTagType TaintTagGeneric = 0;
2828

2929
/// Create a new state in which the value of the statement is marked as tainted.
30-
LLVM_NODISCARD ProgramStateRef addTaint(ProgramStateRef State, const Stmt *S,
31-
const LocationContext *LCtx,
32-
TaintTagType Kind = TaintTagGeneric);
30+
[[nodiscard]] ProgramStateRef addTaint(ProgramStateRef State, const Stmt *S,
31+
const LocationContext *LCtx,
32+
TaintTagType Kind = TaintTagGeneric);
3333

3434
/// Create a new state in which the value is marked as tainted.
35-
LLVM_NODISCARD ProgramStateRef addTaint(ProgramStateRef State, SVal V,
36-
TaintTagType Kind = TaintTagGeneric);
35+
[[nodiscard]] ProgramStateRef addTaint(ProgramStateRef State, SVal V,
36+
TaintTagType Kind = TaintTagGeneric);
3737

3838
/// Create a new state in which the symbol is marked as tainted.
39-
LLVM_NODISCARD ProgramStateRef addTaint(ProgramStateRef State, SymbolRef Sym,
40-
TaintTagType Kind = TaintTagGeneric);
39+
[[nodiscard]] ProgramStateRef addTaint(ProgramStateRef State, SymbolRef Sym,
40+
TaintTagType Kind = TaintTagGeneric);
4141

4242
/// Create a new state in which the pointer represented by the region
4343
/// is marked as tainted.
44-
LLVM_NODISCARD ProgramStateRef addTaint(ProgramStateRef State,
45-
const MemRegion *R,
46-
TaintTagType Kind = TaintTagGeneric);
44+
[[nodiscard]] ProgramStateRef addTaint(ProgramStateRef State,
45+
const MemRegion *R,
46+
TaintTagType Kind = TaintTagGeneric);
4747

48-
LLVM_NODISCARD ProgramStateRef removeTaint(ProgramStateRef State, SVal V);
48+
[[nodiscard]] ProgramStateRef removeTaint(ProgramStateRef State, SVal V);
4949

50-
LLVM_NODISCARD ProgramStateRef removeTaint(ProgramStateRef State,
51-
const MemRegion *R);
50+
[[nodiscard]] ProgramStateRef removeTaint(ProgramStateRef State,
51+
const MemRegion *R);
5252

53-
LLVM_NODISCARD ProgramStateRef removeTaint(ProgramStateRef State,
54-
SymbolRef Sym);
53+
[[nodiscard]] ProgramStateRef removeTaint(ProgramStateRef State, SymbolRef Sym);
5554

5655
/// Create a new state in a which a sub-region of a given symbol is tainted.
5756
/// This might be necessary when referring to regions that can not have an
5857
/// individual symbol, e.g. if they are represented by the default binding of
5958
/// a LazyCompoundVal.
60-
LLVM_NODISCARD ProgramStateRef addPartialTaint(
61-
ProgramStateRef State, SymbolRef ParentSym, const SubRegion *SubRegion,
62-
TaintTagType Kind = TaintTagGeneric);
59+
[[nodiscard]] ProgramStateRef
60+
addPartialTaint(ProgramStateRef State, SymbolRef ParentSym,
61+
const SubRegion *SubRegion,
62+
TaintTagType Kind = TaintTagGeneric);
6363

6464
/// Check if the statement has a tainted value in the given state.
6565
bool isTainted(ProgramStateRef State, const Stmt *S,

clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ template <typename T> class CallDescriptionMap {
190190
CallDescriptionMap(CallDescriptionMap &&) = default;
191191
CallDescriptionMap &operator=(CallDescriptionMap &&) = default;
192192

193-
LLVM_NODISCARD const T *lookup(const CallEvent &Call) const {
193+
[[nodiscard]] const T *lookup(const CallEvent &Call) const {
194194
// Slow path: linear lookup.
195195
// TODO: Implement some sort of fast path.
196196
for (const std::pair<CallDescription, T> &I : LinearMap)
@@ -212,7 +212,7 @@ template <typename T> class CallDescriptionMap {
212212
/// information, such as the precise argument count (see comments for
213213
/// CallEvent::getNumArgs), the called function if it was called through a
214214
/// function pointer, and other information not available syntactically.
215-
LLVM_NODISCARD const T *lookupAsWritten(const CallExpr &Call) const {
215+
[[nodiscard]] const T *lookupAsWritten(const CallExpr &Call) const {
216216
// Slow path: linear lookup.
217217
// TODO: Implement some sort of fast path.
218218
for (const std::pair<CallDescription, T> &I : LinearMap)
@@ -235,7 +235,7 @@ class CallDescriptionSet {
235235
CallDescriptionSet(const CallDescriptionSet &) = delete;
236236
CallDescriptionSet &operator=(const CallDescription &) = delete;
237237

238-
LLVM_NODISCARD bool contains(const CallEvent &Call) const;
238+
[[nodiscard]] bool contains(const CallEvent &Call) const;
239239

240240
/// When available, always prefer lookup with a CallEvent! This function
241241
/// exists only when that is not available, for example, when _only_
@@ -249,7 +249,7 @@ class CallDescriptionSet {
249249
/// information, such as the precise argument count (see comments for
250250
/// CallEvent::getNumArgs), the called function if it was called through a
251251
/// function pointer, and other information not available syntactically.
252-
LLVM_NODISCARD bool containsAsWritten(const CallExpr &CE) const;
252+
[[nodiscard]] bool containsAsWritten(const CallExpr &CE) const;
253253
};
254254

255255
} // namespace ento

clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -899,18 +899,19 @@ class ExprEngine {
899899
/// Note whether this loop has any more iteratios to model. These methods are
900900
/// essentially an interface for a GDM trait. Further reading in
901901
/// ExprEngine::VisitObjCForCollectionStmt().
902-
LLVM_NODISCARD static ProgramStateRef
902+
[[nodiscard]] static ProgramStateRef
903903
setWhetherHasMoreIteration(ProgramStateRef State,
904904
const ObjCForCollectionStmt *O,
905905
const LocationContext *LC, bool HasMoreIteraton);
906906

907-
LLVM_NODISCARD static ProgramStateRef
907+
[[nodiscard]] static ProgramStateRef
908908
removeIterationState(ProgramStateRef State, const ObjCForCollectionStmt *O,
909909
const LocationContext *LC);
910910

911-
LLVM_NODISCARD static bool hasMoreIteration(ProgramStateRef State,
912-
const ObjCForCollectionStmt *O,
913-
const LocationContext *LC);
911+
[[nodiscard]] static bool hasMoreIteration(ProgramStateRef State,
912+
const ObjCForCollectionStmt *O,
913+
const LocationContext *LC);
914+
914915
private:
915916
/// Assuming we construct an array of non-POD types, this method allows us
916917
/// to store which element is to be constructed next.

0 commit comments

Comments
 (0)