Some things from GCC 5
bearophile via Digitalmars-d
digitalmars-d at puremagic.com
Sun Nov 30 02:37:15 PST 2014
Some interesting changes in GCC 5.0:
https://gcc.gnu.org/gcc-5/changes.html
-----------------
A new command-line option -Wlogical-not-parentheses has been
added for the C and C++ compilers, which warns about "logical
not" used on the left hand side operand of a comparison.
bool not_equal(int x, int y) {
return !x == y; // warn here
}
return !(x == y); // first fix-it, to negate comparison.
return (!x) == y; // second fix-it, to silence warning.
Its usefulness:
> Close to 100% true positive. That is hundreds of bugs found in
> millions of
> lines of code. For most cases, evaluating the comparison first
> was the
> correct change. For some others, the '!' was a typo and
> removed. A few
> cases involved macros.
If it's close to 100% positive then perhaps it's worth turning it
into an error in D.
-----------------
There are now intrinsic functions to perform arithmetics with
overflow guards, __builtin_add_overflow, __builtin_sub_overflow
and __builtin_mul_overflow:
void *
calloc (size_t x, size_t y)
{
size_t sz;
if (__builtin_mul_overflow (x, y, &sz))
return NULL;
void *ret = malloc (sz);
if (ret) memset (res, 0, sz);
return ret;
}
They are the same in GCC and LLVM-Clang, so is it worth changing
the API of core.checkedint to make is the same of those
functions, for efficiency and GDC/LDC implementation simplicity?
-----------------
New warnings -Wsuggest-final-types and -Wsuggest-final-methods
helps developers to annotate programs by final specifiers (or
anonymous namespaces) in the cases where code generation
improves. These warnings can be used at compile time, but they
are more useful in combination with link-time optimization.
Some info:
https://gcc.gnu.org/ml/gcc-patches/2014-08/msg00119.html
For D this can become a "tip" from the compiler.
-----------------
C++ Dynamic Arrays, I miss them in D:
http://www.open-std.org/JTC1/sc22/WG21/docs/papers/2013/n3662.html
-----------------
Bye,
bearophile
More information about the Digitalmars-d
mailing list