martin_n_fuller <[email protected]> writes: > GCC 16 doesn't optimize away the unused return value from mpz_class > post-increment in code like "mpz_class a = 1; a++;". > I'm using gcc 16.0.0 on Cygwin. Example code below. Example > compilation: "g++ -o gmp_test -std=c++26 -O3 -march=native -W -Wall > gmp_test.cpp -L/usr/local/lib/ -lgmpxx -lgmp"
GCC 16 isn't yet released. File a GCC bug?
>
> I am not sure what options there are. I would be very happy with
> [[nodiscard]] as an improvement, or a warning in GMP C++ documentation
> that a++ generates a temporary copy.
>
> Martin
>
> #include <gmpxx.h>
>
> void* (*alloc_func_ptr)(size_t);
> size_t alloc_count = 0;
>
> void* allocate_function(size_t alloc_size) {
> alloc_count++;
> return alloc_func_ptr(alloc_size);
> }
>
> int main() {
> mp_get_memory_functions(&alloc_func_ptr, NULL, NULL);
> mp_set_memory_functions(allocate_function, NULL, NULL);
>
> mpz_class a = 1;
> a <<= 1000000;
> alloc_count = 0;
> for (size_t k = 0; k < 1000000; k++) {
> a++;
> }
> printf("Loop allocations %zu\n", alloc_count);
> }
> _______________________________________________
> gmp-bugs mailing list
> [email protected]
> https://gmplib.org/mailman/listinfo/gmp-bugs
signature.asc
Description: PGP signature
_______________________________________________ gmp-bugs mailing list [email protected] https://gmplib.org/mailman/listinfo/gmp-bugs
