[cfe-dev] Diagnosing initialization of deprecated data member?
Stephan Bergmann via cfe-dev
cfe-dev at lists.llvm.org
Thu May 7 01:52:17 PDT 2020
For
> $ cat test.cc
> struct S {
> int x;
> [[deprecated]] int y;
> };
> int main() {
> S s{0, 0};
> }
Clang emits a diagnostic
> $ clang++ test.cc
> test.cc:6:12: warning: 'y' is deprecated [-Wdeprecated-declarations]
> S s{0, 0};
> ^
> test.cc:3:7: note: 'y' has been explicitly marked deprecated here
> [[deprecated]] int y;
> ^
> 1 warning generated.
while e.g. GCC and MSVC do not (as checked with godbolt.org).
Is this deliberate behavior on Clang's part, or just a consequence of
how the code happens to work? Are there opinions on whether or not the
behavior is useful?
(I came across this issue when seeing a commit in LibreOffice where some
> #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
were added apparently to silence exactly the above situation in code
initializing a PyTypeObject struct from
/usr/include/python3.8/cpython/object.h, not even realizing that that
pragma would only be needed by Clang and not by GCC.
FWIW, the standard's recommended practice is "to produce a diagnostic
message in case the program refers to a name or entity other than to
declare it", [dcl.attr.deprecated]/4.)
More information about the cfe-dev
mailing list