This is a continuation of these questions .
Consider the following code:
struct A { private: A* const& this_ref{this}; }; int main() { A a{}; (void)a; }
If compiled with -Wextra , GCC v6.2 and clang v3.9. A warning.
Anyway, with the slightly modified version shown below, they behave differently:
struct A { A* const& this_ref{this}; }; int main() { A a{}; (void)a; }
In this case, GCC does not give any warning, clang gives the same warning as in the previous example.
The warnings are almost identical.
He follows someone from clang:
3: warning: bind reference element 'this_ref' to temporary value [-Wdangling-field]
Which compiler is right?
I would say that GCC is wrong in this case, and I open the problem, but, possibly, on the contrary, because of the secret corner of the language.
c ++ gcc language-lawyer clang this-pointer
skypjack
source share