diff options
| author | Olivier Goffart <ogoffart@woboq.com> | 2015-01-09 09:37:26 +0000 |
|---|---|---|
| committer | Olivier Goffart <ogoffart@woboq.com> | 2015-01-09 09:37:26 +0000 |
| commit | ed13fab4bc65ed8142070f9e8c9dc6e003287f87 (patch) | |
| tree | 6c1e188c10d26e7e551e40db205e172bc724217a /clang | |
| parent | 0a092763e73ed1ab736129fc541058a8aeaa517f (diff) | |
| download | bcm5719-llvm-ed13fab4bc65ed8142070f9e8c9dc6e003287f87.tar.gz bcm5719-llvm-ed13fab4bc65ed8142070f9e8c9dc6e003287f87.zip | |
Fix crash in typo correction while correcting enum within a struct in C
llvm-svn: 225513
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/Sema/SemaExprCXX.cpp | 6 | ||||
| -rw-r--r-- | clang/test/Sema/typo-correction.c | 11 |
2 files changed, 15 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index 6351b7d115f..422398ebeb1 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -5991,8 +5991,10 @@ static ExprResult attemptRecovery(Sema &SemaRef, if (auto *NNS = TC.getCorrectionSpecifier()) Record = NNS->getAsType()->getAsCXXRecordDecl(); if (!Record) - Record = cast<CXXRecordDecl>(ND->getDeclContext()->getRedeclContext()); - R.setNamingClass(Record); + Record = + dyn_cast<CXXRecordDecl>(ND->getDeclContext()->getRedeclContext()); + if (Record) + R.setNamingClass(Record); // Detect and handle the case where the decl might be an implicit // member. diff --git a/clang/test/Sema/typo-correction.c b/clang/test/Sema/typo-correction.c index e4d14654cc9..d8524b9d234 100644 --- a/clang/test/Sema/typo-correction.c +++ b/clang/test/Sema/typo-correction.c @@ -12,3 +12,14 @@ void PR21656() { a = b ? : 0; // expected-warning {{type specifier missing, defaults to 'int'}} \ // expected-error {{use of undeclared identifier 'b'}} + +struct ContainerStuct { + enum { SOME_ENUM }; // expected-note {{'SOME_ENUM' declared here}} +}; + +void func(int arg) { + switch (arg) { + case SOME_ENUM_: + ; // expected-error {{use of undeclared identifier 'SOME_ENUM_'; did you mean 'SOME_ENUM'}} + } +} |

