0

The draft C++ standard lists some requirements on library functions using the phrase "mandates". For example, [util.smartptr.shared.cast] says this about std::static_pointer_cast:

template<class T, class U>
shared_ptr<T> static_pointer_cast(const shared_ptr<U>& r) noexcept;

[...]

Mandates: The expression static_­cast<T*>((U*)nullptr) is well-formed.

Is the compiler required to give an error if this condition isn't met (for example if T is char and U is int), or is it just undefined behavior? [structure.sepcifications] defines "mandates" conditions as rendering the program ill-formed if not met, but it's not clear to me if that must result in an error.

jacobsa
  • 5,719
  • 1
  • 28
  • 60
  • 2
    Yes, "ill-formed" means the compiler must diagnose it. If it's not required to be diagnosed then it's usually "ill formed no diagnostic required". – cigien Aug 22 '20 at 22:17
  • @cigien - That's not true. Ill-formed (on its own) does not mean that a diagnostic is required. For example, a well-formed program is required to satisfy the one-definition rule, but not meeting the one-definition rule (which would mean the program is ill-formed) does not require a diagnostic. – Peter Aug 22 '20 at 22:24
  • 2
    @Peter Yes, and as far as I'm aware, violating ODR is explicitly IFNDR, not just IF. See the dupe, it's one of the example there. – cigien Aug 22 '20 at 22:28
  • The *mandate* in the provided example is designated as **well-formed**. – Eljay Aug 22 '20 at 22:31

0 Answers0