@RichFelker It seemed clear enough to me that you can't inspect the return of dlerror() until dlopen() fails. It's not explicitly called out in POSIX, but it seemed a straight forward case to me, similar to errno. Have you ever seen any non-normative text talking about this?
Exactly. The relevant text is "...that describes the last error that occurred during dynamic linking processing", which is very precise about what dlerror has to return (and precludes "clearing" it on success of dlopen).