[AST][RecoveryAST] Preserve the type by default for recovery expression.

Differential Revision: https://reviews.llvm.org/D82657
This commit is contained in:
Haojian Wu 2020-08-24 14:20:36 +02:00
parent a93514abf2
commit 09e7fe9859
8 changed files with 28 additions and 9 deletions

View File

@ -4043,8 +4043,7 @@ def frecovery_ast : Flag<["-"], "frecovery-ast">,
"encountering semantic errors">;
def fno_recovery_ast : Flag<["-"], "fno-recovery-ast">;
def frecovery_ast_type : Flag<["-"], "frecovery-ast-type">,
HelpText<"Preserve the type for recovery expressions when possible "
"(experimental)">;
HelpText<"Preserve the type for recovery expressions when possible">;
def fno_recovery_ast_type : Flag<["-"], "fno-recovery-ast-type">;
let Group = Action_Group in {

View File

@ -2934,8 +2934,8 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
// Recovery AST still heavily relies on dependent-type machinery.
Opts.RecoveryAST =
Args.hasFlag(OPT_frecovery_ast, OPT_fno_recovery_ast, Opts.CPlusPlus);
Opts.RecoveryASTType =
Args.hasFlag(OPT_frecovery_ast_type, OPT_fno_recovery_ast_type, false);
Opts.RecoveryASTType = Args.hasFlag(
OPT_frecovery_ast_type, OPT_fno_recovery_ast_type, Opts.CPlusPlus);
Opts.HeinousExtensions = Args.hasArg(OPT_fheinous_gnu_extensions);
Opts.AccessControl = !Args.hasArg(OPT_fno_access_control);
Opts.ElideConstructors = !Args.hasArg(OPT_fno_elide_constructors);

View File

@ -67,7 +67,8 @@ void f() { }
// expected-note@-1 {{candidate function [with T = long long, U = int]}}
static_assert(sizeof(f<long long, int>()));
// expected-error@-1 {{call to 'f' is ambiguous}}
// expected-error@-1 {{call to 'f' is ambiguous}} \
expected-error@-1 {{invalid application of 'sizeof' to an incomplete type 'void'}}
template<typename T>
concept C3 = true;

View File

@ -279,7 +279,7 @@ namespace pr12658 {
virtual void f() = 0; // expected-note {{unimplemented pure virtual method 'f' in 'C'}}
};
void foo( C& c ) {}
void foo(const C& c ) {}
void bar( void ) {
foo(C(99)); // expected-error {{allocating an object of abstract class type 'pr12658::C'}}

View File

@ -12,7 +12,7 @@ void f() {
T(a)->m = 7;
int(a)++; // expected-error {{assignment to cast is illegal}}
__extension__ int(a)++; // expected-error {{assignment to cast is illegal}}
__typeof(int)(a,5)<<a; // expected-error {{excess elements in scalar initializer}}
__typeof(int)(a,5)<<a; // expected-error {{excess elements in scalar initializer}} expected-warning {{expression result unused}}
void(a), ++a;
if (int(a)+1) {}
for (int(a)+1;;) {} // expected-warning {{expression result unused}}

View File

@ -86,3 +86,22 @@ void func() {
(T(T())); // expected-error {{call to deleted constructor}}
}
}
// verify the secondary diagnostic "no matching function" is emitted.
namespace test7 {
struct C {
C() = delete; // expected-note {{has been explicitly marked deleted}}
};
void f(C &); // expected-note {{candidate function not viable: expects an l-value for 1st argument}}
void test() {
f(C()); // expected-error {{call to deleted constructor}} \
expected-error {{no matching function for call}}
}
}
// verify the secondary diagnostic "cannot initialize" is emitted.
namespace test8 {
typedef int arr[];
int v = arr(); // expected-error {{array types cannot be value-initialized}} \
expected-error {{cannot initialize a variable of type 'int' with an rvalue of type 'test8::arr'}}
}

View File

@ -6,7 +6,7 @@ void f() {
float v1 = float(1);
int v2 = typeof(int)(1,2); // expected-error {{excess elements in scalar initializer}}
typedef int arr[];
int v3 = arr(); // expected-error {{array types cannot be value-initialized}}
arr(); // expected-error {{array types cannot be value-initialized}}
typedef void fn_ty();
fn_ty(); // expected-error {{cannot create object of function type 'fn_ty'}}
fn_ty(0); // expected-error {{functional-style cast from 'int' to 'fn_ty'}}

View File

@ -173,7 +173,7 @@ namespace PR10053 {
namespace O {
void f(char&); // expected-note {{candidate function not viable}}
int f(char&); // expected-note {{candidate function not viable}}
template<typename T> struct C {
static const int n = f(T()); // expected-error {{no matching function}}