Skip to content

Commit

Permalink
c++11 size test
Browse files Browse the repository at this point in the history
  • Loading branch information
lucylq committed May 3, 2024
1 parent c5598d1 commit 8d66fe5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
13 changes: 6 additions & 7 deletions runtime/core/portable_type/string_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,9 @@ class basic_string_view final {
}

constexpr const_reference at(size_type pos) const {
ET_CHECK_MSG(
pos >= size_,
"string_view::operator[] or string_view::at() out of range");
return at_(pos);
return __ET_UNLIKELY (!(pos >= size_))
? (ET_ASSERT_MESSAGE_EMIT(" (%s): " "string_view::operator[] or string_view::at() out of range", pos >= size_), torch::executor::runtime_abort())
: at_(pos);
}

constexpr const_reference front() const {
Expand Down Expand Up @@ -137,9 +136,9 @@ class basic_string_view final {

constexpr basic_string_view substr(size_type pos = 0, size_type count = npos)
const {
ET_CHECK_MSG(
pos > size_, "basic_string_view::substr parameter out of bounds.");
return substr_(pos, count);
return __ET_UNLIKELY (!(pos > size_))
? (ET_ASSERT_MESSAGE_EMIT(" (%s): " "basic_string_view::substr parameter out of bounds.", pos > size_), torch::executor::runtime_abort())
: substr_(pos, count);
}

constexpr int compare(basic_string_view rhs) const noexcept {
Expand Down
4 changes: 2 additions & 2 deletions test/build_size_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ compiler=$(cc --version)
if [[ $compiler == *"clang"* ]]; then
CXX_FLAGS="$CXX_FLAGS -Werror -Wc++17-extensions -Wc++14-extensions"
elif [[ $compiler == *"cc"* ]]; then
CXX_FLAGS="$CXX_FLAGS -Werror -Wc++17-compat"
CXX_FLAGS="$CXX_FLAGS -Werror -Wc++17-compat -Wc++14-compat"
else
echo "Unknown compiler: $compiler"
exit 1
Expand All @@ -31,7 +31,7 @@ cmake_install_executorch_lib() {
rm -rf cmake-out

retry cmake -DBUCK2="$BUCK2" \
-DCMAKE_CXX_STANDARD=14 \
-DCMAKE_CXX_STANDARD=11 \
-DCMAKE_CXX_STANDARD_REQUIRED=ON \
-DCMAKE_CXX_FLAGS="$CXX_FLAGS" \
-DCMAKE_INSTALL_PREFIX=cmake-out \
Expand Down

0 comments on commit 8d66fe5

Please sign in to comment.