This is an archive of the discontinued LLVM Phabricator instance.

[Clang] Check for abstract parameters only when functions are defined.
ClosedPublic

Authored by cor3ntin on Jun 4 2023, 8:16 AM.

Details

Summary

The C++ standard allows abstract parameters in deleted functions
and in function declarations

The type of a parameter or the return type for a function definition
shall not be a (possibly cv-qualified) class type that is
incomplete or abstract within the function body
unless the function is deleted.

Fixes https://github.com/llvm/llvm-project/issues/63012

Diff Detail

Event Timeline

cor3ntin created this revision.Jun 4 2023, 8:16 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 4 2023, 8:16 AM
cor3ntin requested review of this revision.Jun 4 2023, 8:16 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 4 2023, 8:16 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
cor3ntin added a reviewer: Restricted Project.Jun 4 2023, 8:16 AM
aaron.ballman added inline comments.
clang/lib/Sema/SemaDeclCXX.cpp
6007

This doesn't seem quite right -- we skip bodies for various reasons: https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Parse/Parser.h#L413

Which test case needed this change?

clang/test/CXX/class.derived/class.abstract/p3.cpp
38–41

Whole lotta trailing semi colons that should be removed (you should get all of them, not just theses).

77–79

FIXME can be removed now? Do we need a DR test case for this?

clang/test/CXX/drs/dr6xx.cpp
707–708

Is this fixme still accurate? Should we be changing the resolution from partial to full?

clang/test/SemaCXX/abstract.cpp
369

A mildly horrifying test case to consider:

struct S {
  virtual void func() = 0;
};
void S::func() {}

static_assert(__is_abstract(S));

struct T {
  void func(S) = delete;
  void other(S);
  void yet_another(S) {}
};

We currently don't do good things... https://godbolt.org/z/7vEY3Kz9c

cor3ntin added inline comments.Jun 6 2023, 12:42 PM
clang/test/CXX/drs/dr6xx.cpp
707–708

nah, cf below (L714)

cor3ntin updated this revision to Diff 529045.Jun 6 2023, 2:23 PM
cor3ntin marked 2 inline comments as done.

Address Aaron's comments.

Initially these changes were tracked in
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0929r2.html

I fixed the specific github issue but more work is needed to acertain conformance.

cor3ntin marked 3 inline comments as done.Jun 7 2023, 4:26 AM
aaron.ballman accepted this revision.Jun 7 2023, 9:35 AM
aaron.ballman added a subscriber: rjmccall.

LGTM, though please wait a day or so to land this in case @rjmccall disagrees with my assessment of the Objective-C changes.

clang/test/SemaObjCXX/parameters.mm
14–17

I think this change makes sense for Objective-C as well (this is a declaration and not a definition, at least as I understand things), but pinging @rjmccall just in case I'm wrong.

This revision is now accepted and ready to land.Jun 7 2023, 9:35 AM
rjmccall added inline comments.Jun 7 2023, 12:18 PM
clang/test/SemaObjCXX/parameters.mm
14–17

No, that's right, methods in @interfaces and @protocols are just declarations.

Consistency with the base standard seems like the right way to go here, even those I personally find this rule rather silly. (It's one thing to allow this for deleted methods, but allowing it for declarations?)