Warn once for a deprecated class, and not each instantiation

Jeffrey Walton noloader@gmail.com
Wed Oct 7 20:21:00 GMT 2015

We have a C++ header-only class that needs to change due to a bug. We
marked it as deprecated:

template <class C1, class C2 = X, class C3 = Y>
struct BAD_CLASS
    : ...

} __attribute__((deprecated ("BAD_CLASS will be changing in the near
future due to (1) an implementation bug and (2) an interop issue.")));

Each instantiation produces a separate, multiline warning. The
intention is to warn the user (once), and not repeatedly warn the user
(multiple times). We expect those who are mindful of warnings "get it"
the first time. For others, it does not matter how many times its
repeated because they are going to ignore it.

Is it possible to "warn once" in this situation? If so, how?

Does GCC have something Microsoft's "pragma once(...)" for warnings?

Thanks in advance.

More information about the Gcc-help mailing list