-
-
Notifications
You must be signed in to change notification settings - Fork 471
Removed forced unsigned int cast in type_def bit-shift operators #1178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jwellbelove
merged 5 commits into
ETLCPP:pull-request/#1178-Removed-forced-unsigned-int-cast-in-type_def-bit-shift-operators
from
ockeydockey:feature/RemoveTypeDefUB
Sep 11, 2025
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f22e3aa
Removed UB in type_def bit-shift operators
ockeydockey 4724d01
Changed shift operators to allow both signed and unsigned operands fo…
ockeydockey d17dca8
Fixed constexpr errors for CPP11
ockeydockey b380fce
Changed is_arithmetic checks to use is_integral since valid shifts re…
ockeydockey f7a828a
Removed need for CPP11 since changes are CPP03 compatible
ockeydockey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -290,14 +290,28 @@ namespace etl | |
} | ||
|
||
//********************************************************************* | ||
ETL_CONSTEXPR14 type_def& operator <<=(int rhs) ETL_NOEXCEPT | ||
template <typename T> | ||
ETL_CONSTEXPR | ||
#if ETL_USING_CPP11 | ||
typename etl::enable_if<etl::is_arithmetic<T>::value, type_def&>::type | ||
#else | ||
type_def& | ||
#endif | ||
operator <<=(T rhs) ETL_NOEXCEPT | ||
{ | ||
value <<= rhs; | ||
return *this; | ||
} | ||
|
||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
//********************************************************************* | ||
ETL_CONSTEXPR14 type_def& operator >>=(int rhs) ETL_NOEXCEPT | ||
template <typename T> | ||
ockeydockey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ETL_CONSTEXPR | ||
#if ETL_USING_CPP11 | ||
typename etl::enable_if<etl::is_arithmetic<T>::value, type_def&>::type | ||
#else | ||
type_def& | ||
#endif | ||
operator >>=(T rhs) ETL_NOEXCEPT | ||
{ | ||
value >>= rhs; | ||
return *this; | ||
|
@@ -589,19 +603,59 @@ namespace etl | |
//********************************************************************* | ||
// << operator | ||
//********************************************************************* | ||
friend ETL_CONSTEXPR type_def operator <<(const type_def& lhs, int rhs) ETL_NOEXCEPT | ||
template <typename T> | ||
ockeydockey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
friend ETL_CONSTEXPR | ||
#if ETL_USING_CPP11 | ||
typename etl::enable_if<etl::is_arithmetic<T>::value, type_def>::type | ||
#else | ||
type_def | ||
#endif | ||
operator <<(const type_def& lhs, T rhs) ETL_NOEXCEPT | ||
{ | ||
return type_def(lhs.value << rhs); | ||
} | ||
|
||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
//********************************************************************* | ||
ockeydockey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
template <typename T> | ||
ockeydockey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
friend ETL_CONSTEXPR | ||
#if ETL_USING_CPP11 | ||
typename etl::enable_if<etl::is_arithmetic<T>::value, T>::type | ||
#else | ||
T | ||
#endif | ||
operator <<(T lhs, const type_def& rhs) ETL_NOEXCEPT | ||
{ | ||
return lhs << rhs.value; | ||
} | ||
|
||
//********************************************************************* | ||
// >> operator | ||
//********************************************************************* | ||
friend ETL_CONSTEXPR type_def operator >>(const type_def& lhs, int rhs) ETL_NOEXCEPT | ||
template <typename T> | ||
ockeydockey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
friend ETL_CONSTEXPR | ||
#if ETL_USING_CPP11 | ||
typename etl::enable_if<etl::is_arithmetic<T>::value, type_def>::type | ||
#else | ||
type_def | ||
#endif | ||
operator >>(const type_def& lhs, T rhs) ETL_NOEXCEPT | ||
{ | ||
return type_def(lhs.value >> rhs); | ||
} | ||
|
||
//********************************************************************* | ||
ockeydockey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
template <typename T> | ||
friend ETL_CONSTEXPR | ||
#if ETL_USING_CPP11 | ||
typename etl::enable_if<etl::is_arithmetic<T>::value, T>::type | ||
#else | ||
T | ||
#endif | ||
operator >>(T lhs, const type_def& rhs) ETL_NOEXCEPT | ||
{ | ||
return lhs >> rhs.value; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainSymmetry with ‘T >> type_def’: promotions and negative counts
-#if ETL_USING_CPP11
- typename etl::enable_if<etl::is_arithmetic<T>::value, T>::type
+#if ETL_USING_CPP11
+ typename etl::enable_if<etl::is_integral<T>::value, T>::type Body (outside the hunk): - return lhs >> rhs.value;
+ // ETL_ASSERT(rhs.value >= 0);
+ return lhs >> static_cast<typename etl::make_unsigned<TValue>::type>(rhs.value); 🏁 Script executed: #!/bin/bash
# Locate the definition of type_def to inspect TValue and member 'value'
rg -nP '^(template\s*<[^>]+>\s*)?(class|struct)\s+type_def\b' -C5 include/etl/type_def.h
# Search for any alias or typedef of TValue within the same file
rg -nP 'using\s+TValue' -n include/etl/type_def.h
rg -nP 'typedef\s+.*TValue' -n include/etl/type_def.h
# Show the operator>> implementation context around the original snippet
sed -n '640,680p' include/etl/type_def.h Length of output: 1215 Restrict
🤖 Prompt for AI Agents
|
||
//********************************************************************* | ||
// < operator | ||
//********************************************************************* | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.