This is an archive of the discontinued LLVM Phabricator instance.

[Clang] Do not warn on unused lifetime-extending vars with side effects...
ClosedPublic

Authored by cor3ntin on Mar 29 2022, 8:35 AM.

Diff Detail

Event Timeline

cor3ntin created this revision.Mar 29 2022, 8:35 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 29 2022, 8:35 AM
cor3ntin requested review of this revision.Mar 29 2022, 8:35 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 29 2022, 8:35 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
cor3ntin updated this revision to Diff 418891.Mar 29 2022, 8:36 AM

Cleanup test.

aaron.ballman added inline comments.Apr 5 2022, 7:09 AM
clang/lib/Sema/SemaDecl.cpp
1893–1894
1901
1908–1909
clang/test/SemaCXX/warn-unused-variables.cpp
276–279

I think the difference between Clang and GCC here is that GCC only diagnoses when this function is instantiated: https://godbolt.org/z/f6ddacT97

How do we behave when we instantiate it?

Also, what happens with the test case as-written in the bug report:

struct RAIIWrapper {
    RAIIWrapper();
    ~RAIIWrapper();
};

void foo() {
    auto const  guard = RAIIWrapper();
    auto const& guard2 = RAIIWrapper();
    auto && guard3 = RAIIWrapper();
}
cor3ntin updated this revision to Diff 420530.Apr 5 2022, 8:49 AM
cor3ntin marked an inline comment as done.
  • Address Aaron's comments.
  • Add more tests.
aaron.ballman accepted this revision.Apr 5 2022, 10:40 AM

Thanks, the additional test coverage makes it more clear that the changes are good. Please add a release note when landing though!

This revision is now accepted and ready to land.Apr 5 2022, 10:40 AM
This revision was landed with ongoing or failed builds.Apr 5 2022, 12:03 PM
This revision was automatically updated to reflect the committed changes.

Thanks for the review Aaron <3