r353931 - Look through typedefs in getFunctionTypeWithExceptionSpec

Stephan Bergmann via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 13 01:39:18 PST 2019


Author: sberg
Date: Wed Feb 13 01:39:17 2019
New Revision: 353931

URL: http://llvm.org/viewvc/llvm-project?rev=353931&view=rev
Log:
Look through typedefs in getFunctionTypeWithExceptionSpec

Fixes https://bugs.llvm.org/show_bug.cgi?id=40658

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

Added:
    cfe/trunk/test/AST/function-alias.cpp
Modified:
    cfe/trunk/lib/AST/ASTContext.cpp

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=353931&r1=353930&r2=353931&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Wed Feb 13 01:39:17 2019
@@ -2771,7 +2771,7 @@ QualType ASTContext::getFunctionTypeWith
 
   // Anything else must be a function type. Rebuild it with the new exception
   // specification.
-  const auto *Proto = cast<FunctionProtoType>(Orig);
+  const auto *Proto = Orig->getAs<FunctionProtoType>();
   return getFunctionType(
       Proto->getReturnType(), Proto->getParamTypes(),
       Proto->getExtProtoInfo().withExceptionSpec(ESI));

Added: cfe/trunk/test/AST/function-alias.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/AST/function-alias.cpp?rev=353931&view=auto
==============================================================================
--- cfe/trunk/test/AST/function-alias.cpp (added)
+++ cfe/trunk/test/AST/function-alias.cpp Wed Feb 13 01:39:17 2019
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only %s
+
+// Verify that ASTContext::getFunctionTypeWithExceptionSpec (called through
+// ASTContext::hasSameFunctionTypeIgnoringExceptionSpec from
+// ExprEvaluatorBase::handleCallExpr in lib/AST/ExprConstant.cpp) does not crash
+// for a type alias.
+
+constexpr int f() noexcept { return 0; }
+
+using F = int();
+
+constexpr int g(F * p) { return p(); }
+
+constexpr int n = g(f);




More information about the cfe-commits mailing list