[AST] Dont invalide VarDecl even the default initializaiton is failed.
authorHaojian Wu <hokein.wu@gmail.com>
Fri, 3 Apr 2020 09:00:16 +0000 (11:00 +0200)
committerHaojian Wu <hokein.wu@gmail.com>
Tue, 14 Apr 2020 10:58:48 +0000 (12:58 +0200)
commit9657385960350150b77ed652175b4c3801abd7fa
tree4cdf8199df190c2087f59c77476ec93869d0aa0e
parent38609fa9e42aef24b64055817ed01cd015648608
[AST] Dont invalide VarDecl even the default initializaiton is failed.

Summary:
This patch would cause clang emit more diagnostics, but it is much better than https://reviews.llvm.org/D76831

```cpp
struct A {
  A(int);
  ~A() = delete;
};
void k() {
  A a;
}

```

before the patch:

/tmp/t3.cpp:24:5: error: no matching constructor for initialization of 'A'
  A a;
    ^
/tmp/t3.cpp:20:3: note: candidate constructor not viable: requires 1 argument, but 0 were provided
  A(int);
  ^
/tmp/t3.cpp:19:8: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 0 were provided
struct A {

After the patch:

/tmp/t3.cpp:24:5: error: no matching constructor for initialization of 'A'
  A a;
    ^
/tmp/t3.cpp:20:3: note: candidate constructor not viable: requires 1 argument, but 0 were provided
  A(int);
  ^
/tmp/t3.cpp:19:8: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 0 were provided
struct A {
       ^
/tmp/t3.cpp:24:5: error: attempt to use a deleted function
  A a;
    ^
/tmp/t3.cpp:21:3: note: '~A' has been explicitly marked deleted here
  ~A() = delete;

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D77395
clang/lib/Sema/SemaDecl.cpp
clang/test/AST/ast-dump-invalid-initialized.cpp [new file with mode: 0644]
clang/test/CXX/class.access/p4.cpp
clang/test/CXX/drs/dr3xx.cpp
clang/test/CXX/special/class.ctor/p5-0x.cpp
clang/test/CodeCompletion/invalid-initialized-class.cpp [new file with mode: 0644]
clang/test/SemaCXX/cxx0x-deleted-default-ctor.cpp
clang/test/SemaCXX/virtual-base-used.cpp
clang/test/SemaObjCXX/arc-0x.mm