<div dir="ltr"><div dir="ltr">On Thu, 7 May 2020 at 01:52, Stephan Bergmann via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">For<br>
<br>
> $ cat test.cc<br>
> struct S {<br>
>     int x;<br>
>     [[deprecated]] int y;<br>
> };<br>
> int main() {<br>
>     S s{0, 0};<br>
> }<br>
<br>
Clang emits a diagnostic<br>
<br>
> $ clang++ test.cc<br>
> test.cc:6:12: warning: 'y' is deprecated [-Wdeprecated-declarations]<br>
>     S s{0, 0};<br>
>            ^<br>
> test.cc:3:7: note: 'y' has been explicitly marked deprecated here<br>
>     [[deprecated]] int y;<br>
>       ^<br>
> 1 warning generated.<br>
<br>
while e.g. GCC and MSVC do not (as checked with <a href="http://godbolt.org" rel="noreferrer" target="_blank">godbolt.org</a>).<br>
<br>
Is this deliberate behavior on Clang's part, or just a consequence of <br>
how the code happens to work?  Are there opinions on whether or not the <br>
behavior is useful?<br></blockquote><div><br></div><div>I think it's probably a bug. The C++11 attribute is documented as deprecating the name, not the existence of the entity, so diagnosing a use that doesn't use the name seems somewhat questionable. (It's not obviously a bad choice, though, since the intent is very likely to catch cases that would break if the field is removed, not only if it's renamed.)</div><div><br></div><div>There are a few other warnings channeled through the same path (`DiagnoseUseOfDecl`), such as "availability" warnings, and it's quite likely that some of those *should* still be issued for such cases.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
(I came across this issue when seeing a commit in LibreOffice where some<br>
<br>
> #pragma GCC diagnostic ignored "-Wdeprecated-declarations"<br>
<br>
were added apparently to silence exactly the above situation in code <br>
initializing a PyTypeObject struct from <br>
/usr/include/python3.8/cpython/object.h, not even realizing that that <br>
pragma would only be needed by Clang and not by GCC.<br>
<br>
FWIW, the standard's recommended practice is "to produce a diagnostic <br>
message in case the program refers to a name or entity other than to <br>
declare it", [dcl.attr.deprecated]/4.)<br></blockquote><div><br></div><div>What was the intent in the LibreOffice case? Would they want a warning on "S s{.x = 0, .y = 0};" but not on "S s{0, 0};"?</div></div></div>