Fznamznon updated this revision to Diff 535317.
Fznamznon added a comment.
Add comma and test
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D153857/new/
https://reviews.llvm.org/D153857
Files:
clang/docs/ReleaseNotes.rst
clang/include/clang/Parse/Parser.h
clang/lib/Parse/ParseDecl.cpp
clang/lib/Parse/ParseExprCXX.cpp
clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/p3-0x.cpp
clang/test/CXX/drs/dr19xx.cpp
clang/test/CXX/drs/dr6xx.cpp
clang/test/Parser/cxx11-type-specifier.cpp
Index: clang/test/Parser/cxx11-type-specifier.cpp
===================================================================
--- clang/test/Parser/cxx11-type-specifier.cpp
+++ clang/test/Parser/cxx11-type-specifier.cpp
@@ -7,16 +7,21 @@
};
enum E { e };
+template <typename T>
+struct Template { };
+
void f() {
try {
(void) new constexpr int; // expected-error{{type name does not allow constexpr}}
} catch (constexpr int) { // expected-error{{type name does not allow constexpr}}
}
- // These parse as type definitions, not as type references with braced
- // initializers. Sad but true...
- (void) new struct S {}; // expected-error{{'S' cannot be defined in a type specifier}}
- (void) new enum E { e }; // expected-error{{'E' cannot be defined in a type specifier}}
+ (void) new struct S {};
+ (void) new enum E { e };
+ struct S *a = (1 == 1) ? new struct S : new struct S;
+ struct A *b = (1 == 1) ? new struct A : new struct A; // expected-error 2{{allocation of incomplete type}} // expected-note 2{{forward}}
+
+ (void) new Template<int> {};
}
// And for trailing-type-specifier-seq
Index: clang/test/CXX/drs/dr6xx.cpp
===================================================================
--- clang/test/CXX/drs/dr6xx.cpp
+++ clang/test/CXX/drs/dr6xx.cpp
@@ -1078,9 +1078,10 @@
(void)const_cast<struct E{}*>(0); // expected-error {{cannot be defined in a type specifier}}
(void)sizeof(struct F*);
(void)sizeof(struct F{}*); // expected-error {{cannot be defined in a type specifier}}
- (void)new struct G*;
- (void)new struct G{}*; // expected-error {{cannot be defined in a type specifier}}
+ (void)new struct G*; // expected-note {{forward}}
+ (void)new struct G{}*; // expected-error {{incomplete}}
#if __cplusplus >= 201103L
+ // expected-error@-2 {{expected expression}}
(void)alignof(struct H*);
(void)alignof(struct H{}*); // expected-error {{cannot be defined in a type specifier}}
#endif
Index: clang/test/CXX/drs/dr19xx.cpp
===================================================================
--- clang/test/CXX/drs/dr19xx.cpp
+++ clang/test/CXX/drs/dr19xx.cpp
@@ -194,7 +194,7 @@
enum E : int {1}; // expected-error {{expected identifier}} (not bit-field)
};
auto *p1 = new enum E : int; // expected-error {{only permitted as a standalone declaration}}
- auto *p2 = new enum F : int {}; // expected-error {{cannot be defined in a type specifier}}
+ auto *p2 = new enum F : int {}; // expected-error {{only permitted as a standalone declaration}}
auto *p3 = true ? new enum G : int {}; // expected-error {{forward reference}} expected-error {{incomplete}} expected-note {{declaration}}
auto h() -> enum E : int {}; // expected-error {{only permitted as a standalone declaration}}
Index: clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/p3-0x.cpp
===================================================================
--- clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/p3-0x.cpp
+++ clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/p3-0x.cpp
@@ -21,8 +21,8 @@
for (struct S { S(int) {} } s : Undeclared); // expected-error{{types may not be defined in a for range declaration}}
// expected-error@-1{{use of undeclared identifier 'Undeclared'}}
- new struct T {}; // expected-error {{'T' cannot be defined in a type specifier}}
- new struct A {}; // expected-error {{'A' cannot be defined in a type specifier}}
+ new struct T {}; // expected-error {{allocation of incomplete type 'struct T'}} //expected-note{{forward declaration of 'T'}}
+ new struct A {};
try {} catch (struct U {}) {} // expected-error {{'U' cannot be defined in a type specifier}}
Index: clang/lib/Parse/ParseExprCXX.cpp
===================================================================
--- clang/lib/Parse/ParseExprCXX.cpp
+++ clang/lib/Parse/ParseExprCXX.cpp
@@ -3231,7 +3231,7 @@
// A new-type-id is a simplified type-id, where essentially the
// direct-declarator is replaced by a direct-new-declarator.
MaybeParseGNUAttributes(DeclaratorInfo);
- if (ParseCXXTypeSpecifierSeq(DS))
+ if (ParseCXXTypeSpecifierSeq(DS, DeclaratorContext::CXXNew))
DeclaratorInfo.setInvalidType(true);
else {
DeclaratorInfo.SetSourceRange(DS.getSourceRange());
Index: clang/lib/Parse/ParseDecl.cpp
===================================================================
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -2981,6 +2981,8 @@
return DeclSpecContext::DSC_condition;
case DeclaratorContext::ConversionId:
return DeclSpecContext::DSC_conv_operator;
+ case DeclaratorContext::CXXNew:
+ return DeclSpecContext::DSC_new;
case DeclaratorContext::Prototype:
case DeclaratorContext::ObjCResult:
case DeclaratorContext::ObjCParameter:
@@ -2989,7 +2991,6 @@
case DeclaratorContext::Block:
case DeclaratorContext::ForInit:
case DeclaratorContext::SelectionInit:
- case DeclaratorContext::CXXNew:
case DeclaratorContext::CXXCatch:
case DeclaratorContext::ObjCCatch:
case DeclaratorContext::BlockLiteral:
Index: clang/include/clang/Parse/Parser.h
===================================================================
--- clang/include/clang/Parse/Parser.h
+++ clang/include/clang/Parse/Parser.h
@@ -2217,7 +2217,8 @@
DSC_objc_method_result, // ObjC method result context, enables
// 'instancetype'
DSC_condition, // condition declaration context
- DSC_association // A _Generic selection expression's type association
+ DSC_association, // A _Generic selection expression's type association
+ DSC_new, // C++ new expression
};
/// Is this a context in which we are parsing just a type-specifier (or
@@ -2239,6 +2240,7 @@
case DeclSpecContext::DSC_trailing:
case DeclSpecContext::DSC_alias_declaration:
case DeclSpecContext::DSC_association:
+ case DeclSpecContext::DSC_new:
return true;
}
llvm_unreachable("Missing DeclSpecContext case");
@@ -2287,6 +2289,7 @@
case DeclSpecContext::DSC_trailing:
case DeclSpecContext::DSC_conv_operator:
case DeclSpecContext::DSC_template_arg:
+ case DeclSpecContext::DSC_new:
return AllowDefiningTypeSpec::No;
}
llvm_unreachable("Missing DeclSpecContext case");
@@ -2310,6 +2313,7 @@
case DeclSpecContext::DSC_association:
case DeclSpecContext::DSC_conv_operator:
case DeclSpecContext::DSC_template_arg:
+ case DeclSpecContext::DSC_new:
return false;
}
@@ -2329,6 +2333,7 @@
case DeclSpecContext::DSC_type_specifier:
case DeclSpecContext::DSC_association:
case DeclSpecContext::DSC_conv_operator:
+ case DeclSpecContext::DSC_new:
return true;
case DeclSpecContext::DSC_objc_method_result:
@@ -2351,6 +2356,7 @@
case DeclSpecContext::DSC_trailing:
case DeclSpecContext::DSC_alias_declaration:
case DeclSpecContext::DSC_template_param:
+ case DeclSpecContext::DSC_new:
return ImplicitTypenameContext::Yes;
case DeclSpecContext::DSC_normal:
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -549,6 +549,8 @@
(`#48512 <https://github.com/llvm/llvm-project/issues/48512>`_).
- Fixed a failing assertion when parsing incomplete destructor.
(`#63503 <https://github.com/llvm/llvm-project/issues/63503>`_)
+- Fixed parsing of elaborated type specifier inside of a new expression
+ (`#34341 <https://github.com/llvm/llvm-project/issues/34341>`_)
Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits