Skip to content

Commit

Permalink
Use c++11 for size test (#3509)
Browse files Browse the repository at this point in the history
Summary: Pull Request resolved: #3509

Reviewed By: mergennachin, swolchok

Differential Revision: D57003591

Pulled By: lucylq
  • Loading branch information
lucylq authored and facebook-github-bot committed May 8, 2024
1 parent f9db02a commit bda27d2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
21 changes: 14 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,13 @@ 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 (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 +140,13 @@ 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 (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
6 changes: 3 additions & 3 deletions test/build_size_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ source "$(dirname "${BASH_SOURCE[0]}")/../.ci/scripts/utils.sh"
CXX_FLAGS="-Wno-gnu"
compiler=$(cc --version)
if [[ $compiler == *"clang"* ]]; then
CXX_FLAGS="$CXX_FLAGS -Werror -Wc++17-extensions"
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 bda27d2

Please sign in to comment.