You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Look at the diff, then consider this code
```
#include <iostream>
#include <concepts>
class Uint256_t {
public:
// Conversion operator (explicit)
template <std::integral T>
explicit operator T() const {
std::cout << "Uint256_t conversion operator called\n";
return static_cast<T>(data[0]);
}
int data[4] = {0,0,0,0};
};
class Field {
public:
Field() {}
// Constructor that takes a Uint256_t
Field(int x) {
std::cout << "This is silly!!!!" << std::endl;
}
Field(const Uint256_t& input) {
(void)input;
std::cout << "Field constructor called\n";
// Additional initialization code here
}
};
class Toot {
public:
Toot(Field f) {
(void)f;
}
};
int main() {
Uint256_t uint256_value;
Field x = uint256_value;
Toot t{uint256_value};
return 0;
}
```
With std::integral concept on the cast:
```
Field constructor called
Field constructor called
```
but without! which was caught in practice passing a uint256 to
FieldSponge
```
Field constructor called
Uint256_t conversion operator called
This is silly!!!!
```
This truncated the field mysteriously! Open-ended implicit conversions
are dangerous
---------
Co-authored-by: ludamad <adam@aztecprotocol.com>
0 commit comments