hokein created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
hokein requested review of this revision.

We should not capture the type if the function return type is undeduced.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87350

Files:
  clang/lib/Sema/SemaOverload.cpp
  clang/test/SemaCXX/recovery-expr-type.cpp


Index: clang/test/SemaCXX/recovery-expr-type.cpp
===================================================================
--- clang/test/SemaCXX/recovery-expr-type.cpp
+++ clang/test/SemaCXX/recovery-expr-type.cpp
@@ -105,3 +105,9 @@
 int v = arr(); // expected-error {{array types cannot be value-initialized}} \
                   expected-error {{cannot initialize a variable of type 'int' 
with an rvalue of type 'test8::arr'}}
 }
+
+namespace test9 {
+auto f(); // expected-note {{candidate function not viable}}
+// verify no crash on evaluating the size of undeduced auto type.
+static_assert(sizeof(f(1)), ""); // expected-error {{no matching function for 
call to 'f'}}
+}
Index: clang/lib/Sema/SemaOverload.cpp
===================================================================
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -12853,7 +12853,7 @@
     if (Candidate.Function->isInvalidDecl())
       return;
     QualType T = Candidate.Function->getReturnType();
-    if (T.isNull())
+    if (T.isNull() || T->isUndeducedType())
       return;
     if (!Result)
       Result = T;


Index: clang/test/SemaCXX/recovery-expr-type.cpp
===================================================================
--- clang/test/SemaCXX/recovery-expr-type.cpp
+++ clang/test/SemaCXX/recovery-expr-type.cpp
@@ -105,3 +105,9 @@
 int v = arr(); // expected-error {{array types cannot be value-initialized}} \
                   expected-error {{cannot initialize a variable of type 'int' with an rvalue of type 'test8::arr'}}
 }
+
+namespace test9 {
+auto f(); // expected-note {{candidate function not viable}}
+// verify no crash on evaluating the size of undeduced auto type.
+static_assert(sizeof(f(1)), ""); // expected-error {{no matching function for call to 'f'}}
+}
Index: clang/lib/Sema/SemaOverload.cpp
===================================================================
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -12853,7 +12853,7 @@
     if (Candidate.Function->isInvalidDecl())
       return;
     QualType T = Candidate.Function->getReturnType();
-    if (T.isNull())
+    if (T.isNull() || T->isUndeducedType())
       return;
     if (!Result)
       Result = T;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to