https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110186

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=55837

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Amir Ansari from comment #2)
> The compiler is warning about B::B() = default. That is C++ 11. How can you
> say it has not been updated for C++11?

Because it hasn't.

For the out-of-class `C::C() = default;` definition code will be generated for
that constructor at the point of definition, and the warning code gets a chance
to check it. The fact it happens to use C++11 syntax isn't actually relevant,
the code in GCC that compiles that constructor isn't very different from if
you'd written `C::C() { }` instead.

When you write `B() = default;` it's an inline function that won't generate any
code until/unless instantiated, so I don't think the -Weffc++ warning code even
sees that constructor. If you do use it, the warning code still doesn't see it,
probably because of the way defaulted constructors are handled by the front
end, which hasn't been updated to allow -Weffc++ to work for
defaulted-on-first-declaration functions.

The warnings also don't understand default member initializers (see Bug 55837),
or deduced return types (Bug 85875) and probably other newer features.

Your example would give the same diagnostics for:

struct B {
  // implicitly declared default ctor
  A a;
};
struct C {
  C();
  A a;
};
C::C() { }

The issue is that B::B() is never defined in the code, so the warning never
gets a chance to check it. For a defaulted `B() = default;` that could be
fixed, if somebody cared enough to update -Weffc++ for modern C++.

> Meyer's updated book has a slightly different name:
> 
> Effective Modern C++: 42 Specific Ways to Improve Your Use of C++11 and C++14

And as I said in Bug 16166 comment 3, the warnings don't even match the newer
edition of Effective C++, let alone the Effective Modern C++ replacement.

I continue to recommend that people don't use -Weffc++ unless they're going to
do the work to make it useful again.

Reply via email to