diff options
author | Marc Glisse <marc.glisse@inria.fr> | 2014-01-18 17:41:28 +0100 |
---|---|---|
committer | Marc Glisse <marc.glisse@inria.fr> | 2014-01-18 17:41:28 +0100 |
commit | db517c33de81c84d34a1eca237fbdd1d4d7a3dc1 (patch) | |
tree | d7fbd11a96782104c853c7a2cc2d1688ecb547dd /doc | |
parent | 9e304daadda7ef88a93cd874346629806c8a439c (diff) | |
download | gmp-db517c33de81c84d34a1eca237fbdd1d4d7a3dc1.tar.gz |
Warn about C++11 auto. The second example can be updated if we make it valid later.
Diffstat (limited to 'doc')
-rw-r--r-- | doc/gmp.texi | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/doc/gmp.texi b/doc/gmp.texi index 74f6bd8d3..fca4bd066 100644 --- a/doc/gmp.texi +++ b/doc/gmp.texi @@ -7271,6 +7271,31 @@ void fun (T f, T g) fun2 (f, T(f+g)); // Good @} @end example + +@item C++11 +C++11 provides several new ways in which types can be inferred: @code{auto}, +@code{decltype}, etc. While they can be very convenient, they don't mix well +with expression templates. In this example, the addition is performed twice, +as if we had defined @code{sum} as a macro. + +@example +mpz_class z = 33; +auto sum = z + z; +mpz_class prod = sum * sum; +@end example + +This other example may crash, though some compilers might make it look like +it is working, because the expression @code{z+z} goes out of scope before it +is evaluated. + +@example +mpz_class z = 33; +auto sum = z + z + z; +mpz_class prod = sum * 2; +@end example + +It is thus strongly recommended to avoid @code{auto} anywhere a GMP C++ +expression may appear. @end table |