From d255266a066331d8d7d0808c0e0bc0cda33d647e Mon Sep 17 00:00:00 2001 From: Kaelyn Takata Date: Wed, 7 Jan 2015 21:16:39 +0000 Subject: [PATCH] Handle OpaqueValueExprs more intelligently in the TransformTypos tree transform. Also diagnose typos in the initializer of an invalid C++ declaration. Both issues were hit using the same line of test code, depending on whether the code was treated as C or C++. Fixes PR22092. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@225389 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDecl.cpp | 4 +++- lib/Sema/SemaExprCXX.cpp | 6 ++++++ test/Sema/typo-correction.c | 3 +++ test/SemaCXX/typo-correction-delayed.cpp | 5 +++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 7264d82774..3af60cf299 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -8574,8 +8574,10 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, bool DirectInit, bool TypeMayContainAuto) { // If there is no declaration, there was an error parsing it. Just ignore // the initializer. - if (!RealDecl || RealDecl->isInvalidDecl()) + if (!RealDecl || RealDecl->isInvalidDecl()) { + CorrectDelayedTyposInExpr(Init); return; + } if (CXXMethodDecl *Method = dyn_cast(RealDecl)) { // With declarators parsed the way they are, the parser cannot diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index 1e692ebe25..6351b7d115 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -6141,6 +6141,12 @@ public: ExprResult TransformLambdaExpr(LambdaExpr *E) { return Owned(E); } + ExprResult TransformOpaqueValueExpr(OpaqueValueExpr *E) { + if (Expr *SE = E->getSourceExpr()) + return TransformExpr(SE); + return BaseTransform::TransformOpaqueValueExpr(E); + } + ExprResult Transform(Expr *E) { ExprResult Res; while (true) { diff --git a/test/Sema/typo-correction.c b/test/Sema/typo-correction.c index 04cf0775f1..e4d14654cc 100644 --- a/test/Sema/typo-correction.c +++ b/test/Sema/typo-correction.c @@ -9,3 +9,6 @@ void PR21656() { float x; x = (float)arst; // expected-error-re {{use of undeclared identifier 'arst'{{$}}}} } + +a = b ? : 0; // expected-warning {{type specifier missing, defaults to 'int'}} \ + // expected-error {{use of undeclared identifier 'b'}} diff --git a/test/SemaCXX/typo-correction-delayed.cpp b/test/SemaCXX/typo-correction-delayed.cpp index 49bb14fe8c..e028faad25 100644 --- a/test/SemaCXX/typo-correction-delayed.cpp +++ b/test/SemaCXX/typo-correction-delayed.cpp @@ -152,3 +152,8 @@ namespace PR21947 { int blue; // expected-note {{'blue' declared here}} __typeof blur y; // expected-error {{use of undeclared identifier 'blur'; did you mean 'blue'?}} } + +namespace PR22092 { +a = b ? : 0; // expected-error {{C++ requires a type specifier for all declarations}} \ + // expected-error-re {{use of undeclared identifier 'b'{{$}}}} +} -- 2.40.0