r363622 - Fix crash when checking a dependently-typed reference that is

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 17 14:46:18 PDT 2019


Author: rsmith
Date: Mon Jun 17 14:46:17 2019
New Revision: 363622

URL: http://llvm.org/viewvc/llvm-project?rev=363622&view=rev
Log:
Fix crash when checking a dependently-typed reference that is
initialized from a non-value-dependent initializer.

Modified:
    cfe/trunk/lib/AST/Decl.cpp
    cfe/trunk/test/SemaTemplate/dependent-expr.cpp

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=363622&r1=363621&r2=363622&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Mon Jun 17 14:46:17 2019
@@ -2282,7 +2282,7 @@ bool VarDecl::isUsableInConstantExpressi
   //   declaration is encountered...
   const VarDecl *DefVD = nullptr;
   const Expr *Init = getAnyInitializer(DefVD);
-  if (!Init || Init->isValueDependent())
+  if (!Init || Init->isValueDependent() || getType()->isDependentType())
     return false;
   //   ... if it is a constexpr variable, or it is of reference type or of
   //   const-qualified integral or enumeration type, ...

Modified: cfe/trunk/test/SemaTemplate/dependent-expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/dependent-expr.cpp?rev=363622&r1=363621&r2=363622&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/dependent-expr.cpp (original)
+++ cfe/trunk/test/SemaTemplate/dependent-expr.cpp Mon Jun 17 14:46:17 2019
@@ -63,6 +63,14 @@ namespace test5 {
   };
 }
 
+namespace test6 {
+  template<typename T> T f() {
+    const T &v(0);
+    return v;
+  }
+  int use = f<int>();
+}
+
 namespace PR8795 {
   template <class _CharT> int test(_CharT t)
   {




More information about the cfe-commits mailing list