This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd98c34f4d795: [clang] fix error recovery ICE on copy elision 
when returing invalid variable (authored by mizvekov).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109191

Files:
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/CXX/class/class.init/class.copy.elision/p3.cpp


Index: clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
===================================================================
--- clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
+++ clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
@@ -518,3 +518,37 @@
 template X<int> test_dependent_invalid_decl<int>(); // expected-note 
{{requested here}}
 
 } // namespace test_auto_variables
+
+namespace PR51708 {
+
+class a1;                  // expected-note 4 {{forward declaration of 
'PR51708::a1'}}
+template <class> class A2; // expected-note 4 {{template is declared here}}
+using a2 = A2<int>;
+
+template <class b> b f() {
+  // expected-error@-1 {{incomplete result type 'PR51708::a1' in function 
definition}}
+  // expected-error@-2 {{implicit instantiation of undefined template 
'PR51708::A2<int>}}
+
+  b d;
+  // expected-error@-1 {{variable has incomplete type 'PR51708::a1'}}
+  // expected-error@-2 {{implicit instantiation of undefined template 
'PR51708::A2<int>}}
+
+  return d;
+}
+template a1 f<a1>(); // expected-note-re {{in instantiation {{.*}} requested 
here}}
+template a2 f<a2>(); // expected-note-re {{in instantiation {{.*}} requested 
here}}
+
+template <class b> b g() {
+  // expected-error@-1 {{incomplete result type 'PR51708::a1' in function 
definition}}
+  // expected-error@-2 {{implicit instantiation of undefined template 
'PR51708::A2<int>}}
+
+  b d __attribute__((aligned(1)));
+  // expected-error@-1 {{variable has incomplete type 'PR51708::a1'}}
+  // expected-error@-2 {{implicit instantiation of undefined template 
'PR51708::A2<int>}}
+
+  return d;
+}
+template a1 g<a1>(); // expected-note-re {{in instantiation {{.*}} requested 
here}}
+template a2 g<a2>(); // expected-note-re {{in instantiation {{.*}} requested 
here}}
+
+} // namespace PR51708
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===================================================================
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -1087,7 +1087,7 @@
 
   SemaRef.BuildVariableInstantiation(Var, D, TemplateArgs, LateAttrs, Owner,
                                      StartingScope, InstantiatingVarTemplate);
-  if (D->isNRVOVariable()) {
+  if (D->isNRVOVariable() && !Var->isInvalidDecl()) {
     QualType RT;
     if (auto *F = dyn_cast<FunctionDecl>(DC))
       RT = F->getReturnType();


Index: clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
===================================================================
--- clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
+++ clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
@@ -518,3 +518,37 @@
 template X<int> test_dependent_invalid_decl<int>(); // expected-note {{requested here}}
 
 } // namespace test_auto_variables
+
+namespace PR51708 {
+
+class a1;                  // expected-note 4 {{forward declaration of 'PR51708::a1'}}
+template <class> class A2; // expected-note 4 {{template is declared here}}
+using a2 = A2<int>;
+
+template <class b> b f() {
+  // expected-error@-1 {{incomplete result type 'PR51708::a1' in function definition}}
+  // expected-error@-2 {{implicit instantiation of undefined template 'PR51708::A2<int>}}
+
+  b d;
+  // expected-error@-1 {{variable has incomplete type 'PR51708::a1'}}
+  // expected-error@-2 {{implicit instantiation of undefined template 'PR51708::A2<int>}}
+
+  return d;
+}
+template a1 f<a1>(); // expected-note-re {{in instantiation {{.*}} requested here}}
+template a2 f<a2>(); // expected-note-re {{in instantiation {{.*}} requested here}}
+
+template <class b> b g() {
+  // expected-error@-1 {{incomplete result type 'PR51708::a1' in function definition}}
+  // expected-error@-2 {{implicit instantiation of undefined template 'PR51708::A2<int>}}
+
+  b d __attribute__((aligned(1)));
+  // expected-error@-1 {{variable has incomplete type 'PR51708::a1'}}
+  // expected-error@-2 {{implicit instantiation of undefined template 'PR51708::A2<int>}}
+
+  return d;
+}
+template a1 g<a1>(); // expected-note-re {{in instantiation {{.*}} requested here}}
+template a2 g<a2>(); // expected-note-re {{in instantiation {{.*}} requested here}}
+
+} // namespace PR51708
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===================================================================
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -1087,7 +1087,7 @@
 
   SemaRef.BuildVariableInstantiation(Var, D, TemplateArgs, LateAttrs, Owner,
                                      StartingScope, InstantiatingVarTemplate);
-  if (D->isNRVOVariable()) {
+  if (D->isNRVOVariable() && !Var->isInvalidDecl()) {
     QualType RT;
     if (auto *F = dyn_cast<FunctionDecl>(DC))
       RT = F->getReturnType();
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D109191: [clang] f... Matheus Izvekov via Phabricator via cfe-commits
    • [PATCH] D109191: [cla... Matheus Izvekov via Phabricator via cfe-commits

Reply via email to