Hi,
Please review the attached patch.
It fix a crash while trying to compile the code that is in the testcase (in C
mode). This crash is a regression since 3.5
The problem is that "isCXXClassMember" for the NameDecl of the enum values
returns true even tough we are in C mode. Therefore, the DeclContext is not a
CXXRecordDecl, but just a plain RecordDecl.
I'm taking the least intrusive approach by handling the case in which the cast
would otherwise fail.
Thanks
--
Olivier
>From 64b19f4397b75a68ba5a0e6054fefc2e4ab6ad06 Mon Sep 17 00:00:00 2001
From: Olivier Goffart <[email protected]>
Date: Thu, 8 Jan 2015 21:50:52 +0100
Subject: [PATCH] Fix crash in typo correction while correcting enum within a
struct in C
---
lib/Sema/SemaExprCXX.cpp | 5 +++--
test/Sema/typo-correction.c | 12 ++++++++++++
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp
index 6351b7d..750a40e 100644
--- a/lib/Sema/SemaExprCXX.cpp
+++ b/lib/Sema/SemaExprCXX.cpp
@@ -5991,8 +5991,9 @@ 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/test/Sema/typo-correction.c b/test/Sema/typo-correction.c
index e4d1465..4fbc38f 100644
--- a/test/Sema/typo-correction.c
+++ b/test/Sema/typo-correction.c
@@ -12,3 +12,15 @@ 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'}}
+ }
+}
--
2.2.1
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits