Skip to content

Commit 29908a1

Browse files
committed
[llvm] Add LLVM_CTOR_NODISCARD (llvm#65418)
[[nodiscard]] on constructors is a defect report against C++17. That means that it should be applied retroactively, though older compilers might not know about it and emit warnings. This adds a back-compatibility macro. (cherry picked from commit 11ce3d9)
1 parent ec4cc84 commit 29908a1

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

llvm/include/llvm/MC/MCInstPrinter.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef LLVM_MC_MCINSTPRINTER_H
1010
#define LLVM_MC_MCINSTPRINTER_H
1111

12+
#include "llvm/Support/Compiler.h"
1213
#include "llvm/Support/Format.h"
1314
#include <cstdint>
1415

@@ -97,8 +98,8 @@ class MCInstPrinter {
9798

9899
class WithMarkup {
99100
public:
100-
WithMarkup(raw_ostream &OS, Markup M, bool EnableMarkup,
101-
bool EnableColor);
101+
LLVM_CTOR_NODISCARD WithMarkup(raw_ostream &OS, Markup M, bool EnableMarkup,
102+
bool EnableColor);
102103
~WithMarkup();
103104

104105
template <typename T> WithMarkup &operator<<(T &O) {

llvm/include/llvm/Support/Compiler.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,12 @@
307307
#define LLVM_GSL_POINTER
308308
#endif
309309

310+
#if LLVM_HAS_CPP_ATTRIBUTE(nodiscard) >= 201907L
311+
#define LLVM_CTOR_NODISCARD [[nodiscard]]
312+
#else
313+
#define LLVM_CTOR_NODISCARD
314+
#endif
315+
310316
/// LLVM_EXTENSION - Support compilers where we have a keyword to suppress
311317
/// pedantic diagnostics.
312318
#ifdef __GNUC__

0 commit comments

Comments
 (0)