r225513 - Fix crash in typo correction while correcting enum within a struct in C
Olivier Goffart
ogoffart at woboq.com
Fri Jan 9 01:37:26 PST 2015
Author: ogoffart
Date: Fri Jan 9 03:37:26 2015
New Revision: 225513
URL: http://llvm.org/viewvc/llvm-project?rev=225513&view=rev
Log:
Fix crash in typo correction while correcting enum within a struct in C
Modified:
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/test/Sema/typo-correction.c
Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=225513&r1=225512&r2=225513&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Fri Jan 9 03:37:26 2015
@@ -5991,8 +5991,10 @@ static ExprResult attemptRecovery(Sema &
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.
Modified: cfe/trunk/test/Sema/typo-correction.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/typo-correction.c?rev=225513&r1=225512&r2=225513&view=diff
==============================================================================
--- cfe/trunk/test/Sema/typo-correction.c (original)
+++ cfe/trunk/test/Sema/typo-correction.c Fri Jan 9 03:37:26 2015
@@ -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'}}
+ }
+}
More information about the cfe-commits
mailing list