[PATCH] D141580: [clang] Don't consider a nullptr returned from ActOnTag() as a valid result in ParseClassSpecifier.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 13 06:40:51 PST 2023


hokein updated this revision to Diff 488985.
hokein added a comment.

Check for the ActOnTemplatedFriendTag.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141580/new/

https://reviews.llvm.org/D141580

Files:
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/test/Parser/cxx-undeclared-identifier.cpp
  clang/test/Parser/recovery.cpp
  clang/test/SemaCXX/invalid-template-params.cpp
  clang/test/SemaCXX/rdar42746401.cpp


Index: clang/test/SemaCXX/rdar42746401.cpp
===================================================================
--- clang/test/SemaCXX/rdar42746401.cpp
+++ clang/test/SemaCXX/rdar42746401.cpp
@@ -4,4 +4,4 @@
 class b;
 class c; // expected-note{{forward declaration}}
 
-::b<0> struct c::d // expected-error{{incomplete type}} expected-error{{cannot combine}} expected-error{{expected unqualified-id}}
+::b<0> struct c::d // expected-error{{incomplete type}} expected-error{{expected unqualified-id}}
Index: clang/test/SemaCXX/invalid-template-params.cpp
===================================================================
--- clang/test/SemaCXX/invalid-template-params.cpp
+++ clang/test/SemaCXX/invalid-template-params.cpp
@@ -15,9 +15,8 @@
 public:
   template<typename T0, typename T1 = T0 // missing closing angle bracket
   struct S0 {}; // expected-error {{'S0' cannot be defined in a type specifier}}
-                // expected-error at -1 {{cannot combine with previous 'type-name' declaration specifier}}
-                // expected-error at -2 {{expected ',' or '>' in template-parameter-list}}
-                // expected-error at -3 {{declaration does not declare anything}}
+                // expected-error at -1 {{expected ',' or '>' in template-parameter-list}}
+                // expected-error at -2 {{declaration does not declare anything}}
   C0() : m(new S0<int>) {} // expected-error {{expected '(' for function-style cast or type construction}}
                            // expected-error at -1 {{expected expression}}
   S0<int> *m; // expected-error {{expected member name or ';' after declaration specifiers}}
Index: clang/test/Parser/recovery.cpp
===================================================================
--- clang/test/Parser/recovery.cpp
+++ clang/test/Parser/recovery.cpp
@@ -212,6 +212,6 @@
 enum ::, enum ::; // expected-error 2 {{expected identifier}}
 struct ::__super, struct ::__super; // expected-error 2 {{expected identifier}} expected-error 2 {{expected '::' after '__super'}}
 struct ::template foo, struct ::template bar; // expected-error 2 {{expected identifier}} expected-error 2 {{declaration of anonymous struct must be a definition}} expected-warning {{declaration does not declare anything}}
-struct ::foo struct::; // expected-error {{no struct named 'foo' in the global namespace}} expected-error {{expected identifier}} expected-error {{declaration of anonymous struct must be a definition}}
+struct ::foo struct::; // expected-error {{no struct named 'foo' in the global namespace}} expected-error {{expected identifier}}
 class :: : {} a;  // expected-error {{expected identifier}} expected-error {{expected class name}}
 }
Index: clang/test/Parser/cxx-undeclared-identifier.cpp
===================================================================
--- clang/test/Parser/cxx-undeclared-identifier.cpp
+++ clang/test/Parser/cxx-undeclared-identifier.cpp
@@ -15,5 +15,5 @@
 // PR7180
 int f(a::b::c); // expected-error {{use of undeclared identifier 'a'}}
 
-class Foo::Bar { // expected-error {{use of undeclared identifier 'Foo'}} \
-                 // expected-error {{expected ';' after class}}
+class Foo::Bar { // expected-error {{use of undeclared identifier 'Foo'}}
+                 // expected-error {{expected unqualified-id}}
Index: clang/lib/Parse/ParseDeclCXX.cpp
===================================================================
--- clang/lib/Parse/ParseDeclCXX.cpp
+++ clang/lib/Parse/ParseDeclCXX.cpp
@@ -2034,11 +2034,13 @@
     ProhibitCXX11Attributes(attrs, diag::err_attributes_not_allowed,
                             /*DiagnoseEmptyAttrs=*/true);
 
-    TagOrTempResult = Actions.ActOnTemplatedFriendTag(
-        getCurScope(), DS.getFriendSpecLoc(), TagType, StartLoc, SS, Name,
-        NameLoc, attrs,
-        MultiTemplateParamsArg(TemplateParams ? &(*TemplateParams)[0] : nullptr,
-                               TemplateParams ? TemplateParams->size() : 0));
+    if (auto *FT = Actions.ActOnTemplatedFriendTag(
+            getCurScope(), DS.getFriendSpecLoc(), TagType, StartLoc, SS, Name,
+            NameLoc, attrs,
+            MultiTemplateParamsArg(
+                TemplateParams ? &(*TemplateParams)[0] : nullptr,
+                TemplateParams ? TemplateParams->size() : 0)))
+      TagOrTempResult = FT;
   } else {
     if (TUK != Sema::TUK_Declaration && TUK != Sema::TUK_Definition)
       ProhibitCXX11Attributes(attrs, diag::err_attributes_not_allowed,
@@ -2066,14 +2068,15 @@
     stripTypeAttributesOffDeclSpec(attrs, DS, TUK);
 
     // Declaration or definition of a class type
-    TagOrTempResult = Actions.ActOnTag(
-        getCurScope(), TagType, TUK, StartLoc, SS, Name, NameLoc, attrs, AS,
-        DS.getModulePrivateSpecLoc(), TParams, Owned, IsDependent,
-        SourceLocation(), false, clang::TypeResult(),
-        DSC == DeclSpecContext::DSC_type_specifier,
-        DSC == DeclSpecContext::DSC_template_param ||
-            DSC == DeclSpecContext::DSC_template_type_arg,
-        OffsetOfState, &SkipBody);
+    if (auto *TagDecl = Actions.ActOnTag(
+            getCurScope(), TagType, TUK, StartLoc, SS, Name, NameLoc, attrs, AS,
+            DS.getModulePrivateSpecLoc(), TParams, Owned, IsDependent,
+            SourceLocation(), false, clang::TypeResult(),
+            DSC == DeclSpecContext::DSC_type_specifier,
+            DSC == DeclSpecContext::DSC_template_param ||
+                DSC == DeclSpecContext::DSC_template_type_arg,
+            OffsetOfState, &SkipBody))
+      TagOrTempResult = TagDecl;
 
     // If ActOnTag said the type was dependent, try again with the
     // less common call.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D141580.488985.patch
Type: text/x-patch
Size: 5638 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230113/fedc4b1f/attachment-0001.bin>


More information about the cfe-commits mailing list