[PATCH] D119051: Extend the C++03 definition of POD to include defaulted functions

David Blaikie via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 7 15:27:56 PST 2022


dblaikie added a comment.

In D119051#3350072 <https://reviews.llvm.org/D119051#3350072>, @rnk wrote:

> I would structure this as a LangOpt, and feed the target checks and ABI compat checks into the default setting for it. It could be something like `DefaultedSMFArePOD` / `-f[no-]defaulted-smf-are-pod` (smf being special member functions). The LangOpt default is true, and the driver fills in the value from the target and ABI version in the case of no explicit flag.
>
> I think the DeclCXX changes are probably in the right place. I don't think it makes sense to carry around separate `isPOD` bits according to the C++11 and C++03 rules, just so we can use them later to make these two specific, known ABI-impacting decisions.

Fair enough - had a go at that. Used your naming though in light of @jyknight's suggestion it might be overly specific (but figure we can bikeshed that in parallel with the implementation review)

In D119051#3350276 <https://reviews.llvm.org/D119051#3350276>, @jyknight wrote:

> In D119051#3316026 <https://reviews.llvm.org/D119051#3316026>, @dblaikie wrote:
>
>> Ah, looks like this is the existing https://github.com/itanium-cxx-abi/cxx-abi/issues/66
>
> If you're going to change the ABI, you might as well tackle the rest of the differences mentioned in that issue while you're in there. That is, neither marking anything "= delete", nor creating a user-defined move assignment operator should mark it non-pod according to the GCC-compatible rules.

Fair point - I think I've got those cases covered (see updated test case - happy to expand that further if desired - testing each case separately, or the like)? No member functions/ctor marked deleted, and no user-defined move assignment operator make the type non-pod.

I tested this a bit more robustly end-to-end like this:

  struct t1 {
    t1() = default;
    t1(const t1&) = delete;
    t1(t1&&) = default;
    void operator=(t1&&);
    ~t1() = delete;
    int a;
    char c;
  };
  struct t2 : t1 {
    char c;
  };
  int x[sizeof(t2) == 3 * sizeof(int) ? 1 : -1];

$ clang-tot test.cpp -c  -target x86_64-scei-ps4 
test.cpp:13:7: error: 'x' declared as an array with a negative size
int x[sizeof(t2) == 3 * sizeof(int) ? 1 : -1];

  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

1 error generated.
$ clang-tot test.cpp -c  -target x86_64-scei-ps4 -fdefaulted-smf-are-pod
$ clang-tot test.cpp -c  -target x86_64-unknown-darwin 
test.cpp:13:7: error: 'x' declared as an array with a negative size
int x[sizeof(t2) == 3 * sizeof(int) ? 1 : -1];

  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

1 error generated.
$ clang-tot test.cpp -c  -target x86_64-unknown-darwin -fdefaulted-smf-are-pod
$ clang-tot test.cpp -c  -target x86_64-unknown-linux
$ clang-tot test.cpp -c  -target x86_64-unknown-linux -fno-defaulted-smf-are-pod
test.cpp:13:7: error: 'x' declared as an array with a negative size
int x[sizeof(t2) == 3 * sizeof(int) ? 1 : -1];

  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

1 error generated.

  


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D119051/new/

https://reviews.llvm.org/D119051



More information about the cfe-commits mailing list