summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/lib/Sema/SemaExprCXX.cpp9
-rw-r--r--clang/test/Parser/cxx1z-init-statement.cpp8
-rw-r--r--clang/test/SemaCXX/return.cpp2
-rw-r--r--clang/test/SemaCXX/typo-correction-crash.cpp2
4 files changed, 16 insertions, 5 deletions
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index ea1de0c6428..2cd00f8218a 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -1222,7 +1222,14 @@ Sema::ActOnCXXTypeConstructExpr(ParsedType TypeRep,
if (!TInfo)
TInfo = Context.getTrivialTypeSourceInfo(Ty, SourceLocation());
- return BuildCXXTypeConstructExpr(TInfo, LParenLoc, exprs, RParenLoc);
+ auto Result = BuildCXXTypeConstructExpr(TInfo, LParenLoc, exprs, RParenLoc);
+ // Avoid creating a non-type-dependent expression that contains typos.
+ // Non-type-dependent expressions are liable to be discarded without
+ // checking for embedded typos.
+ if (!Result.isInvalid() && Result.get()->isInstantiationDependent() &&
+ !Result.get()->isTypeDependent())
+ Result = CorrectDelayedTyposInExpr(Result.get());
+ return Result;
}
/// ActOnCXXTypeConstructExpr - Parse construction of a specified type.
diff --git a/clang/test/Parser/cxx1z-init-statement.cpp b/clang/test/Parser/cxx1z-init-statement.cpp
index e8621babaa8..c118522e8c4 100644
--- a/clang/test/Parser/cxx1z-init-statement.cpp
+++ b/clang/test/Parser/cxx1z-init-statement.cpp
@@ -10,6 +10,7 @@ int f() {
if (T(f()), g, h; f()) {} // expected-error {{not yet supported}}
if (T f(); f()) {} // expected-error {{not yet supported}}
if (T f(), g, h; f()) {} // expected-error {{not yet supported}}
+ if (T(n) = 0; n) {} // expected-error {{not yet supported}}
// init-statement expressions
if (T{f()}; f()) {} // expected-error {{not yet supported}}
@@ -20,6 +21,7 @@ int f() {
if (T(n){g}) {}
if (T f()) {} // expected-error {{function type}}
if (T f(), g, h) {} // expected-error {{function type}}
+ if (T(n) = 0) {}
// condition expressions
if (T(f())) {}
@@ -27,9 +29,9 @@ int f() {
if (T(f()), g, h) {} // expected-warning 2{{unused}}
if (T{f()}, g, h) {} // expected-warning 2{{unused}}
- // none of the above
- // FIXME: This causes a typo-correction crash, as does "void f() { +T(n)(g); }"
- //if (T(n)(g)) {} // expected-err-FIXME {{not a function}}
+ // none of the above, disambiguated as expression (can't be a declaration)
+ if (T(n)(g)) {} // expected-error {{undeclared identifier 'n'}}
+ if (T(n)(int())) {} // expected-error {{undeclared identifier 'n'}}
// Likewise for 'switch'
switch (int n; n) {} // expected-error {{not yet supported}}
diff --git a/clang/test/SemaCXX/return.cpp b/clang/test/SemaCXX/return.cpp
index 8c1664516a7..db289240d1c 100644
--- a/clang/test/SemaCXX/return.cpp
+++ b/clang/test/SemaCXX/return.cpp
@@ -118,5 +118,5 @@ void cxx_unresolved_expr() {
// CXXUnresolvedConstructExpr, and the missing ')' gives it an invalid source
// location for its rparen. Check that emitting a diag on the range of the
// expr doesn't assert.
- return int(undeclared, 4; // expected-error {{expected ')'}} expected-note{{to match this '('}} expected-error {{void function 'cxx_unresolved_expr' should not return a value}} expected-error {{use of undeclared identifier 'undeclared'}}
+ return int(undeclared, 4; // expected-error {{expected ')'}} expected-note{{to match this '('}} expected-error {{use of undeclared identifier 'undeclared'}}
}
diff --git a/clang/test/SemaCXX/typo-correction-crash.cpp b/clang/test/SemaCXX/typo-correction-crash.cpp
index 6349937ccd9..0b8383dbafe 100644
--- a/clang/test/SemaCXX/typo-correction-crash.cpp
+++ b/clang/test/SemaCXX/typo-correction-crash.cpp
@@ -17,3 +17,5 @@ typedef int type;
}
struct FooRecord { };
FooRecord::NestedNamespace::type x; // expected-error {{no member named 'NestedNamespace' in 'FooRecord'; did you mean 'BarNamespace::NestedNamespace'?}}
+
+void cast_expr(int g) { +int(n)(g); } // expected-error {{undeclared identifier 'n'}}
OpenPOWER on IntegriCloud