I can't see any evidence in the C++17 wording that attributes are inherited by overriding functions.
The most relevant section I can find is the rules for overriding:
[class.virtual]/2:
If a virtual member function vf
is declared in a class Base
and in a class Derived
, derived directly or indirectly from Base
, a member function vf
with the same name, parameter-type-list (11.3.5), cv-qualification, and ref-qualifier (or absence of same) as Base::vf
is declared, then Derived::vf
is also virtual (whether or not it is so declared) and it overrides Base::vf
. [..]
While this passage attacks the problem from a slightly different angle, I think it's enough to show that only virtualness is "inherited" (and that attributes don't come into play at all when deciding whether one function overrides another). That being said, I think this is slightly underspecified and could do with a clarifying note at the very least.
Of course, this quickly gets complicated. Given the below example:
struct B {
[[nodiscard]] virtual bool foo() { return true; }
};
struct D : B {
bool foo() override { return false; }
};
int main() {
D().foo();
}
Clang will not issue a warning. However, access the function through a base pointer and it will.
struct B {
[[nodiscard]] virtual bool foo() { return true; }
};
struct D : B {
bool foo() override { return false; }
};
int main() {
D d;
((B*)&d)->foo();
}
What that means for your question, I'm not sure.
Again, I'd like to see a bit more guidance from the standard on this topic.