From: Richard Smith Date: Mon, 17 Jun 2019 21:46:17 +0000 (+0000) Subject: Fix crash when checking a dependently-typed reference that is X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d8450eac7b8a65d2332a074d4fdafbf4738a0b6b;p=clang Fix crash when checking a dependently-typed reference that is initialized from a non-value-dependent initializer. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@363622 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index aeb7963f90..bcb9f05ca3 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -2282,7 +2282,7 @@ bool VarDecl::isUsableInConstantExpressions(ASTContext &Context) const { // 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, ... diff --git a/test/SemaTemplate/dependent-expr.cpp b/test/SemaTemplate/dependent-expr.cpp index 7195c9d48d..bb1e239c34 100644 --- a/test/SemaTemplate/dependent-expr.cpp +++ b/test/SemaTemplate/dependent-expr.cpp @@ -63,6 +63,14 @@ namespace test5 { }; } +namespace test6 { + template T f() { + const T &v(0); + return v; + } + int use = f(); +} + namespace PR8795 { template int test(_CharT t) {