vendredi 3 novembre 2017

Are attributes of a type inherited in derived types?

Consider this code:

struct [[nodiscard]] Result { };
struct DiscardableResult: public Result { };

Result func1()
{ return Result(); }

DiscardableResult func2()
{ return DiscardableResult(); }

void testFunc()
{
    func1();
    func2();
}

All versions of Clang, and GCC 7.x or newer, will only warn for the func1() call. GCC 6.x however also warns for the func2() call.

Which behavior is correct? Should DiscardableResult inherit the [[nodiscard]] attribute, or does inheritance not apply to attributes according to the standard?

Aucun commentaire:

Enregistrer un commentaire