Skip to content

Commit 96a4abc

Browse files
Add null violation checks for std::unique_ptr, std::shared_ptr, std::optional and std::expected to prevent UB (#945)
* `assert_not_null` now verifies std::unique_ptr, std::shared_ptr, std::optional and std::expected in addition to the original null pointer check These states are considered to be "null" and will result in a violation error: - std::unique_ptr that owns nothing - std::shared_ptr with no managed object - std::optional with no value - std::expected containing an unexpected value * Update test-results for clang & gcc * Update some more clang & gcc test results
1 parent c902f2b commit 96a4abc

File tree

57 files changed

+502
-57
lines changed

Some content is hidden

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

57 files changed

+502
-57
lines changed

include/cpp2util.h

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@
240240
#ifndef CPP2_NO_EXCEPTIONS
241241
#include <exception>
242242
#endif
243+
#ifdef __cpp_lib_expected
244+
#include <expected>
245+
#endif
243246
#if defined(__cpp_lib_format) || (defined(_MSC_VER) && _MSC_VER >= 1929)
244247
#include <format>
245248
#endif
@@ -451,19 +454,67 @@ auto inline Testing = contract_group(
451454
);
452455

453456

454-
// Null pointer deref checking
457+
// Check for invalid dereference or indirection which would result in undefined behavior.
458+
//
459+
// - Null pointer
460+
// - std::unique_ptr that owns nothing
461+
// - std::shared_ptr with no managed object
462+
// - std::optional with no value
463+
// - std::expected containing an unexpected value
464+
//
465+
// Note: For naming simplicity we consider all the above cases to be "null" states so that
466+
// we can write: `*assert_not_null(object)`.
455467
//
456-
auto assert_not_null(auto&& p CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto)
468+
template<typename T>
469+
concept UniquePtr = std::is_same_v<T, std::unique_ptr<typename T::element_type, typename T::deleter_type>>;
470+
471+
template<typename T>
472+
concept SharedPtr = std::is_same_v<T, std::shared_ptr<typename T::element_type>>;
473+
474+
template<typename T>
475+
concept Optional = std::is_same_v<T, std::optional<typename T::value_type>>;
476+
477+
#ifdef __cpp_lib_expected
478+
479+
template<typename T>
480+
concept Expected = std::is_same_v<T, std::expected<typename T::value_type, typename T::error_type>>;
481+
482+
#endif
483+
484+
auto assert_not_null(auto&& arg CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) -> decltype(auto)
457485
{
458486
// NOTE: This "!= T{}" test may or may not work for STL iterators. The standard
459487
// doesn't guarantee that using == and != will reliably report whether an
460488
// STL iterator has the default-constructed value. So use it only for raw *...
461-
if constexpr (std::is_pointer_v<CPP2_TYPEOF(p)>) {
462-
if (p == CPP2_TYPEOF(p){}) {
489+
if constexpr (std::is_pointer_v<CPP2_TYPEOF(arg)>) {
490+
if (arg == CPP2_TYPEOF(arg){}) {
463491
Null.report_violation("dynamic null dereference attempt detected" CPP2_SOURCE_LOCATION_ARG);
464492
};
465493
}
466-
return CPP2_FORWARD(p);
494+
else if constexpr (UniquePtr<CPP2_TYPEOF(arg)>) {
495+
if (!arg) {
496+
Null.report_violation("std::unique_ptr is empty" CPP2_SOURCE_LOCATION_ARG);
497+
}
498+
}
499+
else if constexpr (SharedPtr<CPP2_TYPEOF(arg)>) {
500+
if (!arg) {
501+
Null.report_violation("std::shared_ptr is empty" CPP2_SOURCE_LOCATION_ARG);
502+
}
503+
}
504+
else if constexpr (Optional<CPP2_TYPEOF(arg)>) {
505+
if (!arg.has_value()) {
506+
Null.report_violation("std::optional does not contain a value" CPP2_SOURCE_LOCATION_ARG);
507+
}
508+
}
509+
#ifdef __cpp_lib_expected
510+
else if constexpr (Expected<CPP2_TYPEOF(arg)>) {
511+
if (!arg.has_value()) {
512+
Null.report_violation("std::expected has an unexpected value" CPP2_SOURCE_LOCATION_ARG);
513+
}
514+
}
515+
#endif
516+
517+
return CPP2_FORWARD(arg);
467518
}
468519

469520
// Subscript bounds checking
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
fine: () -> int =
3+
{
4+
up:= unique.new<int>(1);
5+
sp:= shared.new<int>(2);
6+
op: std::optional<int> = (3);
7+
ex: std::expected<int, bool> = (4);
8+
9+
return up* + sp* + op* + ex*;
10+
}
11+
12+
bad_expected_access: () -> int =
13+
{
14+
ex: std::expected<int, bool> = std::unexpected(false);
15+
return ex*;
16+
}
17+
18+
main: () -> int =
19+
{
20+
return fine() + bad_expected_access();
21+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
fine: () -> int =
3+
{
4+
up:= unique.new<int>(1);
5+
sp:= shared.new<int>(2);
6+
op: std::optional<int> = (3);
7+
8+
return up* + sp* + op*;
9+
}
10+
11+
bad_optional_access: () -> int =
12+
{
13+
op: std::optional<int> = std::nullopt;
14+
return op*;
15+
}
16+
17+
main: () -> int =
18+
{
19+
return fine() + bad_optional_access();
20+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
fine: () -> int =
3+
{
4+
up:= unique.new<int>(1);
5+
sp:= shared.new<int>(2);
6+
op: std::optional<int> = (3);
7+
8+
return up* + sp* + op*;
9+
}
10+
11+
bad_shared_ptr_access: () -> int =
12+
{
13+
sp:= std::make_shared<int>(1);
14+
sp.reset();
15+
return sp*;
16+
}
17+
18+
main: () -> int =
19+
{
20+
return fine() + bad_shared_ptr_access();
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
fine: () -> int =
3+
{
4+
up:= unique.new<int>(1);
5+
sp:= shared.new<int>(2);
6+
op: std::optional<int> = (3);
7+
8+
return up* + sp* + op*;
9+
}
10+
11+
bad_unique_ptr_access: () -> int =
12+
{
13+
up:= std::make_unique<int>(1);
14+
up.reset();
15+
return up*;
16+
}
17+
18+
main: () -> int =
19+
{
20+
return fine() + bad_unique_ptr_access();
21+
}

regression-tests/test-results/apple-clang-14/pure2-assert-expected-not-null.cpp.execution

Whitespace-only changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
pure2-assert-expected-not-null.cpp2:7:10: error: no member named 'expected' in namespace 'std'
2+
std::expected<int,bool> ex {4};
3+
~~~~~^
4+
pure2-assert-expected-not-null.cpp2:7:22: error: expected '(' for function-style cast or type construction
5+
std::expected<int,bool> ex {4};
6+
~~~^
7+
pure2-assert-expected-not-null.cpp2:9:165: error: use of undeclared identifier 'ex'
8+
return *cpp2::assert_not_null(std::move(up)) + *cpp2::assert_not_null(std::move(sp)) + *cpp2::assert_not_null(std::move(op)) + *cpp2::assert_not_null(std::move(ex));
9+
^
10+
pure2-assert-expected-not-null.cpp2:14:10: error: no member named 'expected' in namespace 'std'
11+
std::expected<int,bool> ex {std::unexpected(false)};
12+
~~~~~^
13+
pure2-assert-expected-not-null.cpp2:14:22: error: expected '(' for function-style cast or type construction
14+
std::expected<int,bool> ex {std::unexpected(false)};
15+
~~~^
16+
pure2-assert-expected-not-null.cpp2:15:45: error: use of undeclared identifier 'ex'
17+
return *cpp2::assert_not_null(std::move(ex));
18+
^
19+
6 errors generated.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Null safety violation: std::optional does not contain a value
2+
libc++abi: terminating

regression-tests/test-results/apple-clang-14/pure2-assert-optional-not-null.cpp.output

Whitespace-only changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Null safety violation: std::shared_ptr is empty
2+
libc++abi: terminating

regression-tests/test-results/apple-clang-14/pure2-assert-shared-ptr-not-null.cpp.output

Whitespace-only changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Null safety violation: std::unique_ptr is empty
2+
libc++abi: terminating

regression-tests/test-results/apple-clang-14/pure2-assert-unique-ptr-not-null.cpp.output

Whitespace-only changes.
Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,118 +1,118 @@
11
mixed-bugfix-for-ufcs-non-local.cpp2:13:12: error: a lambda expression cannot appear in this context
22
template<t<CPP2_UFCS_NONLOCAL(f)(o)> UnnamedTypeParam1_1> bool inline constexpr v0 = false;// Fails on GCC ([GCC109781][]) and Clang 12 (a lambda expression cannot appear in this context)
33
^
4-
../../../include/cpp2util.h:885:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
4+
../../../include/cpp2util.h:936:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
55
#define CPP2_UFCS_NONLOCAL(...) CPP2_UFCS_(,(),,__VA_ARGS__)
66
^
7-
../../../include/cpp2util.h:866:53: note: expanded from macro 'CPP2_UFCS_'
7+
../../../include/cpp2util.h:917:53: note: expanded from macro 'CPP2_UFCS_'
88
#define CPP2_UFCS_(LAMBDADEFCAPT,QUALID,TEMPKW,...) \
99
^
1010
mixed-bugfix-for-ufcs-non-local.cpp2:15:3: error: a lambda expression cannot appear in this context
1111
t<CPP2_UFCS_NONLOCAL(f)(o)> inline constexpr v1 = t<true>();// Fails on Clang 12 (lambda in unevaluated context).
1212
^
13-
../../../include/cpp2util.h:885:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
13+
../../../include/cpp2util.h:936:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
1414
#define CPP2_UFCS_NONLOCAL(...) CPP2_UFCS_(,(),,__VA_ARGS__)
1515
^
16-
../../../include/cpp2util.h:866:53: note: expanded from macro 'CPP2_UFCS_'
16+
../../../include/cpp2util.h:917:53: note: expanded from macro 'CPP2_UFCS_'
1717
#define CPP2_UFCS_(LAMBDADEFCAPT,QUALID,TEMPKW,...) \
1818
^
1919
mixed-bugfix-for-ufcs-non-local.cpp2:21:12: error: a lambda expression cannot appear in this context
2020
template<t<CPP2_UFCS_NONLOCAL(f)(o)> UnnamedTypeParam1_2> auto g() -> void;
2121
^
22-
../../../include/cpp2util.h:885:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
22+
../../../include/cpp2util.h:936:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
2323
#define CPP2_UFCS_NONLOCAL(...) CPP2_UFCS_(,(),,__VA_ARGS__)
2424
^
25-
../../../include/cpp2util.h:866:53: note: expanded from macro 'CPP2_UFCS_'
25+
../../../include/cpp2util.h:917:53: note: expanded from macro 'CPP2_UFCS_'
2626
#define CPP2_UFCS_(LAMBDADEFCAPT,QUALID,TEMPKW,...) \
2727
^
2828
mixed-bugfix-for-ufcs-non-local.cpp2:23:36: error: a lambda expression cannot appear in this context
2929
auto g([[maybe_unused]] cpp2::in<t<CPP2_UFCS_NONLOCAL(f)(o)>> unnamed_param_1) -> void;
3030
^
31-
../../../include/cpp2util.h:885:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
31+
../../../include/cpp2util.h:936:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
3232
#define CPP2_UFCS_NONLOCAL(...) CPP2_UFCS_(,(),,__VA_ARGS__)
3333
^
34-
../../../include/cpp2util.h:866:53: note: expanded from macro 'CPP2_UFCS_'
34+
../../../include/cpp2util.h:917:53: note: expanded from macro 'CPP2_UFCS_'
3535
#define CPP2_UFCS_(LAMBDADEFCAPT,QUALID,TEMPKW,...) \
3636
^
3737
mixed-bugfix-for-ufcs-non-local.cpp2:27:29: error: a lambda expression cannot appear in this context
3838
[[nodiscard]] auto h() -> t<CPP2_UFCS_NONLOCAL(f)(o)>;
3939
^
40-
../../../include/cpp2util.h:885:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
40+
../../../include/cpp2util.h:936:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
4141
#define CPP2_UFCS_NONLOCAL(...) CPP2_UFCS_(,(),,__VA_ARGS__)
4242
^
43-
../../../include/cpp2util.h:866:53: note: expanded from macro 'CPP2_UFCS_'
43+
../../../include/cpp2util.h:917:53: note: expanded from macro 'CPP2_UFCS_'
4444
#define CPP2_UFCS_(LAMBDADEFCAPT,QUALID,TEMPKW,...) \
4545
^
4646
mixed-bugfix-for-ufcs-non-local.cpp2:31:12: error: a lambda expression cannot appear in this context
4747
template<t<CPP2_UFCS_NONLOCAL(f)(o)> UnnamedTypeParam1_3> using a = bool;// Fails on GCC ([GCC109781][]) and Clang 12 (a lambda expression cannot appear in this context)
4848
^
49-
../../../include/cpp2util.h:885:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
49+
../../../include/cpp2util.h:936:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
5050
#define CPP2_UFCS_NONLOCAL(...) CPP2_UFCS_(,(),,__VA_ARGS__)
5151
^
52-
../../../include/cpp2util.h:866:53: note: expanded from macro 'CPP2_UFCS_'
52+
../../../include/cpp2util.h:917:53: note: expanded from macro 'CPP2_UFCS_'
5353
#define CPP2_UFCS_(LAMBDADEFCAPT,QUALID,TEMPKW,...) \
5454
^
5555
mixed-bugfix-for-ufcs-non-local.cpp2:33:12: error: a lambda expression cannot appear in this context
5656
template<t<CPP2_UFCS_NONLOCAL(f)(o)> UnnamedTypeParam1_4> auto inline constexpr b = false;// Fails on GCC ([GCC109781][]).
5757
^
58-
../../../include/cpp2util.h:885:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
58+
../../../include/cpp2util.h:936:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
5959
#define CPP2_UFCS_NONLOCAL(...) CPP2_UFCS_(,(),,__VA_ARGS__)
6060
^
61-
../../../include/cpp2util.h:866:53: note: expanded from macro 'CPP2_UFCS_'
61+
../../../include/cpp2util.h:917:53: note: expanded from macro 'CPP2_UFCS_'
6262
#define CPP2_UFCS_(LAMBDADEFCAPT,QUALID,TEMPKW,...) \
6363
^
6464
mixed-bugfix-for-ufcs-non-local.cpp2:35:13: error: a lambda expression cannot appear in this context
6565
using c = t<CPP2_UFCS_NONLOCAL(f)(o)>;// Fails on Clang 12 (lambda in unevaluated context) and Clang 12 (a lambda expression cannot appear in this context)
6666
^
67-
../../../include/cpp2util.h:885:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
67+
../../../include/cpp2util.h:936:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
6868
#define CPP2_UFCS_NONLOCAL(...) CPP2_UFCS_(,(),,__VA_ARGS__)
6969
^
70-
../../../include/cpp2util.h:866:53: note: expanded from macro 'CPP2_UFCS_'
70+
../../../include/cpp2util.h:917:53: note: expanded from macro 'CPP2_UFCS_'
7171
#define CPP2_UFCS_(LAMBDADEFCAPT,QUALID,TEMPKW,...) \
7272
^
7373
mixed-bugfix-for-ufcs-non-local.cpp2:37:29: error: a lambda expression cannot appear in this context
7474
auto inline constexpr d = t<CPP2_UFCS_NONLOCAL(f)(o)>();// Fails on Clang 12 (lambda in unevaluated context).
7575
^
76-
../../../include/cpp2util.h:885:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
76+
../../../include/cpp2util.h:936:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
7777
#define CPP2_UFCS_NONLOCAL(...) CPP2_UFCS_(,(),,__VA_ARGS__)
7878
^
79-
../../../include/cpp2util.h:866:53: note: expanded from macro 'CPP2_UFCS_'
79+
../../../include/cpp2util.h:917:53: note: expanded from macro 'CPP2_UFCS_'
8080
#define CPP2_UFCS_(LAMBDADEFCAPT,QUALID,TEMPKW,...) \
8181
^
8282
mixed-bugfix-for-ufcs-non-local.cpp2:21:12: error: a lambda expression cannot appear in this context
8383
template<t<CPP2_UFCS_NONLOCAL(f)(o)> UnnamedTypeParam1_2> auto g() -> void{}// Fails on GCC ([GCC109781][]) and Clang 12 (a lambda expression cannot appear in this context)
8484
^
85-
../../../include/cpp2util.h:885:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
85+
../../../include/cpp2util.h:936:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
8686
#define CPP2_UFCS_NONLOCAL(...) CPP2_UFCS_(,(),,__VA_ARGS__)
8787
^
88-
../../../include/cpp2util.h:866:53: note: expanded from macro 'CPP2_UFCS_'
88+
../../../include/cpp2util.h:917:53: note: expanded from macro 'CPP2_UFCS_'
8989
#define CPP2_UFCS_(LAMBDADEFCAPT,QUALID,TEMPKW,...) \
9090
^
9191
mixed-bugfix-for-ufcs-non-local.cpp2:23:36: error: a lambda expression cannot appear in this context
9292
auto g([[maybe_unused]] cpp2::in<t<CPP2_UFCS_NONLOCAL(f)(o)>> unnamed_param_1) -> void{}// Fails on Clang 12 (lambda in unevaluated context).
9393
^
94-
../../../include/cpp2util.h:885:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
94+
../../../include/cpp2util.h:936:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
9595
#define CPP2_UFCS_NONLOCAL(...) CPP2_UFCS_(,(),,__VA_ARGS__)
9696
^
97-
../../../include/cpp2util.h:866:53: note: expanded from macro 'CPP2_UFCS_'
97+
../../../include/cpp2util.h:917:53: note: expanded from macro 'CPP2_UFCS_'
9898
#define CPP2_UFCS_(LAMBDADEFCAPT,QUALID,TEMPKW,...) \
9999
^
100100
mixed-bugfix-for-ufcs-non-local.cpp2:27:29: error: a lambda expression cannot appear in this context
101101
[[nodiscard]] auto h() -> t<CPP2_UFCS_NONLOCAL(f)(o)> { return o; }// Fails on Clang 12 (lambda in unevaluated context).
102102
^
103-
../../../include/cpp2util.h:885:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
103+
../../../include/cpp2util.h:936:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
104104
#define CPP2_UFCS_NONLOCAL(...) CPP2_UFCS_(,(),,__VA_ARGS__)
105105
^
106-
../../../include/cpp2util.h:866:53: note: expanded from macro 'CPP2_UFCS_'
106+
../../../include/cpp2util.h:917:53: note: expanded from macro 'CPP2_UFCS_'
107107
#define CPP2_UFCS_(LAMBDADEFCAPT,QUALID,TEMPKW,...) \
108108
^
109109
mixed-bugfix-for-ufcs-non-local.cpp2:41:79: error: lambda expression in an unevaluated operand
110110
inline CPP2_CONSTEXPR bool u::c = [](cpp2::in<std::type_identity_t<decltype(CPP2_UFCS_NONLOCAL(f)(o))>> x) mutable -> auto { return x; }(true);// Fails on Clang 12 (lambda in unevaluated context).
111111
^
112-
../../../include/cpp2util.h:885:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
112+
../../../include/cpp2util.h:936:59: note: expanded from macro 'CPP2_UFCS_NONLOCAL'
113113
#define CPP2_UFCS_NONLOCAL(...) CPP2_UFCS_(,(),,__VA_ARGS__)
114114
^
115-
../../../include/cpp2util.h:866:53: note: expanded from macro 'CPP2_UFCS_'
115+
../../../include/cpp2util.h:917:53: note: expanded from macro 'CPP2_UFCS_'
116116
#define CPP2_UFCS_(LAMBDADEFCAPT,QUALID,TEMPKW,...) \
117117
^
118118
13 errors generated.

regression-tests/test-results/clang-12/pure2-assert-expected-not-null.cpp.execution

Whitespace-only changes.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
pure2-assert-expected-not-null.cpp2:7:22: error: expected '(' for function-style cast or type construction
2+
std::expected<int,bool> ex {4};
3+
~~~^
4+
pure2-assert-expected-not-null.cpp2:7:10: error: no member named 'expected' in namespace 'std'; did you mean 'unexpected'?
5+
std::expected<int,bool> ex {4};
6+
~~~~~^~~~~~~~
7+
unexpected
8+
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/exception:92:8: note: 'unexpected' declared here
9+
void unexpected() __attribute__ ((__noreturn__));
10+
^
11+
pure2-assert-expected-not-null.cpp2:9:165: error: use of undeclared identifier 'ex'
12+
return *cpp2::assert_not_null(std::move(up)) + *cpp2::assert_not_null(std::move(sp)) + *cpp2::assert_not_null(std::move(op)) + *cpp2::assert_not_null(std::move(ex));
13+
^
14+
pure2-assert-expected-not-null.cpp2:14:22: error: expected '(' for function-style cast or type construction
15+
std::expected<int,bool> ex {std::unexpected(false)};
16+
~~~^
17+
pure2-assert-expected-not-null.cpp2:14:10: error: no member named 'expected' in namespace 'std'; did you mean 'unexpected'?
18+
std::expected<int,bool> ex {std::unexpected(false)};
19+
~~~~~^~~~~~~~
20+
unexpected
21+
/usr/bin/../lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/exception:92:8: note: 'unexpected' declared here
22+
void unexpected() __attribute__ ((__noreturn__));
23+
^
24+
pure2-assert-expected-not-null.cpp2:15:45: error: use of undeclared identifier 'ex'
25+
return *cpp2::assert_not_null(std::move(ex));
26+
^
27+
6 errors generated.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Null safety violation: std::optional does not contain a value
2+
terminate called without an active exception

regression-tests/test-results/clang-12/pure2-assert-optional-not-null.cpp.output

Whitespace-only changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Null safety violation: std::shared_ptr is empty
2+
terminate called without an active exception

regression-tests/test-results/clang-12/pure2-assert-shared-ptr-not-null.cpp.output

Whitespace-only changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Null safety violation: std::unique_ptr is empty
2+
terminate called without an active exception

regression-tests/test-results/clang-12/pure2-assert-unique-ptr-not-null.cpp.output

Whitespace-only changes.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
pure2-bugfix-for-ufcs-noexcept.cpp2:5:26: error: lambda expression in an unevaluated operand
22
static_assert(noexcept(CPP2_UFCS(swap)(t(), t())));// Fails on Clang 12 (lambda in unevaluated context) and GCC 10 (static assertion failed)
33
^
4-
../../../include/cpp2util.h:882:59: note: expanded from macro 'CPP2_UFCS'
4+
../../../include/cpp2util.h:933:59: note: expanded from macro 'CPP2_UFCS'
55
#define CPP2_UFCS(...) CPP2_UFCS_(&,(),,__VA_ARGS__)
66
^
7-
../../../include/cpp2util.h:866:53: note: expanded from macro 'CPP2_UFCS_'
7+
../../../include/cpp2util.h:917:53: note: expanded from macro 'CPP2_UFCS_'
88
#define CPP2_UFCS_(LAMBDADEFCAPT,QUALID,TEMPKW,...) \
99
^
1010
1 error generated.

0 commit comments

Comments
 (0)