Skip to content

Commit

Permalink
let EST_Uninstantiated in FunctionProtoType::canThrow return
Browse files Browse the repository at this point in the history
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
  • Loading branch information
zhouzhouyi-hub authored and Erich Keane committed Mar 16, 2022
1 parent 4c9bfec commit 30adb9f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clang/lib/AST/Type.cpp
Expand Up @@ -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:
Expand All @@ -3347,6 +3346,7 @@ CanThrowResult FunctionProtoType::canThrow() const {
return CT_Can;
return CT_Dependent;

case EST_Uninstantiated:
case EST_DependentNoexcept:
return CT_Dependent;
}
Expand Down
32 changes: 32 additions & 0 deletions 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
}


0 comments on commit 30adb9f

Please sign in to comment.