[PATCH] D39133: [Sema] Better fix for tags defined inside an enumeration (PR28903).
Volodymyr Sapsai via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 20 12:05:07 PDT 2017
vsapsai created this revision.
When we encounter an opening parenthesis and parse the rest as type
cast, use DeclSpecContext DSC_type_specifier so we hit the existing check
that prevents defining tags in contexts where type specifier is expected.
This reverts implementation done in r313386, r313894, and keeps the tests.
rdar://problem/28530809
https://reviews.llvm.org/D39133
Files:
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Parse/ParseExpr.cpp
clang/lib/Sema/SemaDecl.cpp
clang/test/CXX/drs/dr5xx.cpp
clang/test/SemaCXX/enum.cpp
Index: clang/test/SemaCXX/enum.cpp
===================================================================
--- clang/test/SemaCXX/enum.cpp
+++ clang/test/SemaCXX/enum.cpp
@@ -114,7 +114,7 @@
// PR28903
struct PR28903 {
enum {
- PR28903_A = (enum { // expected-error-re {{'PR28903::(anonymous enum at {{.*}})' cannot be defined in an enumeration}}
+ PR28903_A = (enum { // expected-error-re {{'PR28903::(anonymous enum at {{.*}})' cannot be defined in a type specifier}}
PR28903_B,
PR28903_C = PR28903_B
})
Index: clang/test/CXX/drs/dr5xx.cpp
===================================================================
--- clang/test/CXX/drs/dr5xx.cpp
+++ clang/test/CXX/drs/dr5xx.cpp
@@ -424,7 +424,7 @@
while (const n = 0) {} // expected-error {{requires a type specifier}}
for (const n = 0; // expected-error {{requires a type specifier}}
const m = 0; ) {} // expected-error {{requires a type specifier}}
- sizeof(const); // expected-error {{requires a type specifier}}
+ sizeof(const); // expected-error {{expected a type}}
struct S {
const n; // expected-error {{requires a type specifier}}
operator const(); // expected-error {{expected a type}}
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -14012,13 +14012,6 @@
Invalid = true;
}
- if (!Invalid && getLangOpts().CPlusPlus && TUK == TUK_Definition &&
- DC->getDeclKind() == Decl::Enum) {
- Diag(New->getLocation(), diag::err_type_defined_in_enum)
- << Context.getTagDeclType(New);
- Invalid = true;
- }
-
// Maybe add qualifier info.
if (SS.isNotEmpty()) {
if (SS.isSet()) {
Index: clang/lib/Parse/ParseExpr.cpp
===================================================================
--- clang/lib/Parse/ParseExpr.cpp
+++ clang/lib/Parse/ParseExpr.cpp
@@ -2373,7 +2373,7 @@
// Parse the type declarator.
DeclSpec DS(AttrFactory);
- ParseSpecifierQualifierList(DS);
+ ParseSpecifierQualifierList(DS, AS_none, DSC_type_specifier);
Declarator DeclaratorInfo(DS, Declarator::TypeNameContext);
ParseDeclarator(DeclaratorInfo);
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1349,8 +1349,6 @@
"%0 cannot be defined in a type alias template">;
def err_type_defined_in_condition : Error<
"%0 cannot be defined in a condition">;
-def err_type_defined_in_enum : Error<
- "%0 cannot be defined in an enumeration">;
def note_pure_virtual_function : Note<
"unimplemented pure virtual method %0 in %1">;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39133.119680.patch
Type: text/x-patch
Size: 2787 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171020/de9e4ec1/attachment.bin>
More information about the cfe-commits
mailing list