[PATCH] D158540: Improve error message for constexpr constructors of virtual base classes

Nouman Amir via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 11 13:24:42 PDT 2023


NoumanAmir657 added a comment.

**Code:**

  struct Base {
   constexpr Base() = default;
  };
  struct Derived : virtual Base {
    constexpr Derived() = default;
  };
  
  struct NoCopyMove {
    constexpr NoCopyMove() {}
    NoCopyMove(const NoCopyMove&);
    NoCopyMove(NoCopyMove&&);
  };
  struct S2 {
    constexpr S2() = default;
    constexpr S2(const S2&) = default;
    constexpr S2(S2&&) = default; 
    NoCopyMove ncm;
  };

**Error Generated**

  ../../llvm-test/x.cpp:5:3: error: default constructor cannot be 'constexpr' in a class with virtual base class
      5 |   constexpr Derived() = default;
        |   ^
  ../../llvm-test/x.cpp:4:18: note: virtual base class declared here
      4 | struct Derived : virtual Base {
        |                  ^
  ../../llvm-test/x.cpp:15:3: error: defaulted definition of copy constructor is not constexpr
     15 |   constexpr S2(const S2&) = default;
        |   ^
  ../../llvm-test/x.cpp:16:3: error: defaulted definition of move constructor is not constexpr
     16 |   constexpr S2(S2&&) = default; 
        |   ^
  3 errors generated.

@aaron.ballman do you mean like this? This now generates different diagnostics depending on whether a virtual base class is present or not


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

https://reviews.llvm.org/D158540



More information about the cfe-commits mailing list