This is an archive of the discontinued LLVM Phabricator instance.

[clang] improving diagnotics for invalid constexpr defaulted special membres
AbandonedPublic

Authored by Tyker on Jun 11 2019, 5:29 AM.

Details

Summary

this patch improves diagnostic for invalid constexpr defaulted special members by adding notes explaining why the special member cannot be constexpr.

example
input:

01 struct B {};
02 
03 struct C : virtual B {
04 };
05 
06 struct D {
07   C c;
08 };
09 
10 struct A : D {
11   constexpr A() = default;
12 };
13 
14 union U {
15   A a;
16   int b;
17   constexpr U() = default;
18 };
19 
20 struct E {
21   ~E() {}
22 };
23 
24 struct F {
25   E e;
26   constexpr F& operator=(const F&) =default;
27 };

output with patch:

test.cpp:11:3: error: defaulted definition of default constructor is not constexpr because:
  constexpr A() = default;
  ^
test.cpp:10:12: note: base class 'D' of 'A' has a non-constexpr implicit default constructor
struct A : D {
           ^
test.cpp:7:5: note: non-static data member 'c' of 'D' has a non-constexpr implicit default constructor
  C c;
    ^
test.cpp:3:12: note: 'C' inherits virtually from 'B'
struct C : virtual B {
           ^
test.cpp:17:3: error: defaulted definition of default constructor is not constexpr because:
  constexpr U() = default;
  ^
note: unions require exactly one non-static data member initializer to have a constexpr default constructor
test.cpp:26:3: error: defaulted definition of copy assignment operator is not constexpr because:
  constexpr F& operator=(const F&) =default;
  ^
note: 'F' is not a literal type
3 errors generated.

I didn't adapt exitsing tests yet because the diagnostics emitted are likely be adapted during review.

Diff Detail

Event Timeline

Tyker created this revision.Jun 11 2019, 5:29 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 11 2019, 5:29 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
Tyker updated this revision to Diff 204041.Jun 11 2019, 5:33 AM
Tyker updated this revision to Diff 217694.Aug 28 2019, 11:31 AM

Rebased on current master

@rsmith Ping

Tyker abandoned this revision.Aug 21 2022, 10:35 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 21 2022, 10:35 AM