[clang] 30adb9f - let EST_Uninstantiated in FunctionProtoType::canThrow return

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 16 07:09:47 PDT 2022


Author: Zhouyi Zhou
Date: 2022-03-16T07:09:42-07:00
New Revision: 30adb9fd279785d18f9902ba980c7d8b31a6c8d7

URL: https://github.com/llvm/llvm-project/commit/30adb9fd279785d18f9902ba980c7d8b31a6c8d7
DIFF: https://github.com/llvm/llvm-project/commit/30adb9fd279785d18f9902ba980c7d8b31a6c8d7.diff

LOG: let EST_Uninstantiated in FunctionProtoType::canThrow return
CT_Dependent

When compile following code without -std=c++17, clang will abort by
llvm_unreachable:

class A {
  public:

  static const char X;

};
const char A::X = 0;

template<typename U> void func() noexcept(U::X);

template<class... B, char x>
void foo(void(B...) noexcept(x)) {}

void bar()
{

  foo(func<A>);

}

So, my solution is to let EST_Uninstantiated in
FunctionProtoType::canThrow return CT_Dependent

Differential Revision: https://reviews.llvm.org/D121498

Added: 
    clang/test/SemaTemplate/class-template-noexcept.cpp

Modified: 
    clang/lib/AST/Type.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 8579d697868fd..08a95669ac9fd 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -3325,7 +3325,6 @@ CanThrowResult FunctionProtoType::canThrow() const {
   switch (getExceptionSpecType()) {
   case EST_Unparsed:
   case EST_Unevaluated:
-  case EST_Uninstantiated:
     llvm_unreachable("should not call this with unresolved exception specs");
 
   case EST_DynamicNone:
@@ -3347,6 +3346,7 @@ CanThrowResult FunctionProtoType::canThrow() const {
         return CT_Can;
     return CT_Dependent;
 
+  case EST_Uninstantiated:
   case EST_DependentNoexcept:
     return CT_Dependent;
   }

diff  --git a/clang/test/SemaTemplate/class-template-noexcept.cpp b/clang/test/SemaTemplate/class-template-noexcept.cpp
new file mode 100644
index 0000000000000..5c4ac090f3166
--- /dev/null
+++ b/clang/test/SemaTemplate/class-template-noexcept.cpp
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -verify %s
+// RUN: %clang_cc1 -std=c++11 -verify %s
+// RUN: %clang_cc1 -std=c++17 -verify %s
+// RUN: %clang_cc1 -std=c++1z -verify %s
+#if __cplusplus >= 201703
+// expected-no-diagnostics
+#endif
+class A {
+public:
+  static const char X;
+};
+const char A::X = 0;
+
+template<typename U> void func() noexcept(U::X);
+
+template<class... B, char x>
+#if __cplusplus >= 201703
+void foo(void(B...) noexcept(x)) {} 
+#else
+void foo(void(B...) noexcept(x)) {} // expected-note{{candidate template ignored}}
+#endif
+
+void bar()
+{
+#if __cplusplus >= 201703
+  foo(func<A>);
+#else
+  foo(func<A>);	// expected-error{{no matching function for call}}
+#endif	
+}
+
+


        


More information about the cfe-commits mailing list