Skip to content

Commit 04ebbeb

Browse files
committed
Retroactively update template/variant.hpp with nodiscard for bad_variant_access (nonstd-lite-project issue 74)
See commit b36014f
1 parent 7e3bce8 commit 04ebbeb

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

template/variant.hpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@
4747
# define variant_CONFIG_OMIT_VARIANT_ALTERNATIVE_T_MACRO 0
4848
#endif
4949

50+
// Control marking class bad_variant_access with [[nodiscard]]]:
51+
52+
#if !defined(variant_CONFIG_NO_NODISCARD)
53+
# define variant_CONFIG_NO_NODISCARD 0
54+
#else
55+
# define variant_CONFIG_NO_NODISCARD 1
56+
#endif
57+
5058
// Control presence of exception handling (try and auto discover):
5159

5260
#ifndef variant_CONFIG_NO_EXCEPTIONS
@@ -364,7 +372,7 @@ namespace nonstd {
364372

365373
// Presence of C++17 language features:
366374

367-
// no flag
375+
#define variant_HAVE_NODISCARD variant_CPP17_000
368376

369377
// Presence of C++ library features:
370378

@@ -404,6 +412,12 @@ namespace nonstd {
404412
# define variant_nullptr NULL
405413
#endif
406414

415+
#if variant_HAVE_NODISCARD && !variant_CONFIG_NO_NODISCARD
416+
# define variant_nodiscard [[nodiscard]]
417+
#else
418+
# define variant_nodiscard /*[[nodiscard]]*/
419+
#endif
420+
407421
#if variant_HAVE_OVERRIDE
408422
# define variant_override override
409423
#else
@@ -1141,7 +1155,7 @@ static const std::size_t variant_npos = static_cast<std::size_t>( -1 );
11411155

11421156
// 19.7.11 Class bad_variant_access
11431157

1144-
class bad_variant_access : public std::exception
1158+
class variant_nodiscard bad_variant_access : public std::exception
11451159
{
11461160
public:
11471161
#if variant_CPP11_OR_GREATER

0 commit comments

Comments
 (0)