This is an archive of the discontinued LLVM Phabricator instance.

[SemaCXX] Validate destructor is valid for dependent classes
ClosedPublic

Authored by royjacobson on Aug 1 2022, 1:49 PM.

Details

Summary

We didn't check that a destructor's name matches the directly enclosing class if the class was dependent.
I enabled the check we already had for non-dependent types, which seems to work. Added appropriate tests.

Fixes GitHub issue #56772

Diff Detail

Event Timeline

royjacobson created this revision.Aug 1 2022, 1:49 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 1 2022, 1:49 PM

Fix the C++20 check

royjacobson published this revision for review.Aug 1 2022, 2:44 PM
royjacobson retitled this revision from [SemaCXX] Fix destructor name accepts-invalid bug. to [SemaCXX] Validate destructor is valid for dependent classes.
royjacobson edited the summary of this revision. (Show Details)
royjacobson added reviewers: erichkeane, shafik.
Herald added a project: Restricted Project. · View Herald TranscriptAug 1 2022, 2:44 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
shafik added a comment.Aug 1 2022, 7:00 PM

LGTM but let's have Erich take a look.

clang/lib/Sema/SemaDecl.cpp
11499

The FIXME goes back a while, I wonder how long ago we fixed this.

erichkeane accepted this revision.Aug 2 2022, 6:46 AM

Hmm... I'm a little shocked that didn't error before, while we did the 2nd pass through the destructor. A little shocking this made it this far...

The fix looks fine to me, I wish I knew why we had that check there, but I got lost in the subversion history.

Anyway, LGTM with 1 nit.. ALSO needs a release note.

clang/test/SemaCXX/member-class-11.cpp
30

Nit: Need newline at end of file (C++98 rule).

This revision is now accepted and ready to land.Aug 2 2022, 6:46 AM
royjacobson edited the summary of this revision. (Show Details)

Add newline and release notes.

This does not work for friend declarations.

template <typename T>
struct A {
  friend T::S::~S();
private:
  static constexpr int secret = 42;
};

struct Q {
  struct S { ~S(); };
};

Q::S::~S() {
  void foo(int);
  foo(A<Q>::secret);
}