Skip to content

Commit 658d307

Browse files
Disable some clang conversion warnings in cpp2util.h and cppfront itself (#1212)
* Disable clang conversion warnings when compiling with -Wconversion cppfront and cpp2util.h use signed integer types for indices and container sizes so disable signed-to-unsigned conversion warnings. cppfront also uses implicit conversions from string literal to bool for: `assert(!"message")` so disable those warnings too. * Update regression tests caused by line number changes in `cpp2util.h` * Removed dependency on `!"string literal"` * Address `.size()` narrowing warnings Using the answer we recommend for everyone else, so model the right behavior here --------- Co-authored-by: Herb Sutter <[email protected]>
1 parent c618ed5 commit 658d307

25 files changed

+89
-69
lines changed

include/cpp2util.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,12 @@
302302
#include <vector>
303303
#endif
304304

305+
// cpp2util.h uses signed integer types for indices and container sizes
306+
// so disable clang signed-to-unsigned conversion warnings in this header.
307+
#ifdef __clang__
308+
#pragma clang diagnostic push
309+
#pragma clang diagnostic ignored "-Wsign-conversion"
310+
#endif
305311

306312
//-----------------------------------------------------------------------
307313
//
@@ -2833,4 +2839,9 @@ using cpp2::cpp2_new;
28332839
#define CPP2_REQUIRES_(...) requires (__VA_ARGS__)
28342840
#endif
28352841

2842+
// Restore clang signed-to-unsigned conversion warnings
2843+
#ifdef __clang__
2844+
#pragma clang diagnostic pop
28362845
#endif
2846+
2847+
#endif // CPP2_CPP2UTIL_H
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
../../../include/cpp2util.h(964) decltype(auto) cpp2::impl::assert_in_bounds(auto &&, std::source_location) [arg = 5, x:auto = std::vector<int>]: Bounds safety violation: out of bounds access attempt detected - attempted access at index 5, [min,max] range is [0,4]
1+
../../../include/cpp2util.h(970) decltype(auto) cpp2::impl::assert_in_bounds(auto &&, std::source_location) [arg = 5, x:auto = std::vector<int>]: Bounds safety violation: out of bounds access attempt detected - attempted access at index 5, [min,max] range is [0,4]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
../../../include/cpp2util.h(776) : Bounds safety violation
1+
../../../include/cpp2util.h(782) : Bounds safety violation
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
../../../include/cpp2util.h(776) : Contract violation: fill: value must contain at least count elements
1+
../../../include/cpp2util.h(782) : Contract violation: fill: value must contain at least count elements
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
sending error to my framework... [dynamic null dereference attempt detected]
2-
from source location: ../../../include/cpp2util.h(855) decltype(auto) cpp2::impl::assert_not_null(auto &&, std::source_location) [arg:auto = int *&]
2+
from source location: ../../../include/cpp2util.h(861) decltype(auto) cpp2::impl::assert_not_null(auto &&, std::source_location) [arg:auto = int *&]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
../../../include/cpp2util.h(855) decltype(auto) cpp2::impl::assert_not_null(auto &&, std::source_location) [arg:auto = std::expected<int, bool>]: Null safety violation: std::expected has an unexpected value
1+
../../../include/cpp2util.h(861) decltype(auto) cpp2::impl::assert_not_null(auto &&, std::source_location) [arg:auto = std::expected<int, bool>]: Null safety violation: std::expected has an unexpected value
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
../../../include/cpp2util.h(855) decltype(auto) cpp2::impl::assert_not_null(auto &&, std::source_location) [arg:auto = std::optional<int>]: Null safety violation: std::optional does not contain a value
1+
../../../include/cpp2util.h(861) decltype(auto) cpp2::impl::assert_not_null(auto &&, std::source_location) [arg:auto = std::optional<int>]: Null safety violation: std::optional does not contain a value
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
../../../include/cpp2util.h(855) decltype(auto) cpp2::impl::assert_not_null(auto &&, std::source_location) [arg:auto = std::shared_ptr<int>]: Null safety violation: std::shared_ptr is empty
1+
../../../include/cpp2util.h(861) decltype(auto) cpp2::impl::assert_not_null(auto &&, std::source_location) [arg:auto = std::shared_ptr<int>]: Null safety violation: std::shared_ptr is empty
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
../../../include/cpp2util.h(855) decltype(auto) cpp2::impl::assert_not_null(auto &&, std::source_location) [arg:auto = std::unique_ptr<int>]: Null safety violation: std::unique_ptr is empty
1+
../../../include/cpp2util.h(861) decltype(auto) cpp2::impl::assert_not_null(auto &&, std::source_location) [arg:auto = std::unique_ptr<int>]: Null safety violation: std::unique_ptr is empty
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
../../../include/cpp2util.h(964) decltype(auto) cpp2::impl::assert_in_bounds(auto &&, std::source_location) [arg = 5, x:auto = std::vector<int>]: Bounds safety violation: out of bounds access attempt detected - attempted access at index 5, [min,max] range is [0,4]
1+
../../../include/cpp2util.h(970) decltype(auto) cpp2::impl::assert_in_bounds(auto &&, std::source_location) [arg = 5, x:auto = std::vector<int>]: Bounds safety violation: out of bounds access attempt detected - attempted access at index 5, [min,max] range is [0,4]

0 commit comments

Comments
 (0)