]> granicus.if.org Git - clang/commitdiff
Fix crash when checking a dependently-typed reference that is
authorRichard Smith <richard-llvm@metafoo.co.uk>
Mon, 17 Jun 2019 21:46:17 +0000 (21:46 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Mon, 17 Jun 2019 21:46:17 +0000 (21:46 +0000)
initialized from a non-value-dependent initializer.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@363622 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/Decl.cpp
test/SemaTemplate/dependent-expr.cpp

index aeb7963f9004542e575aaadc4ae9176fc66e033e..bcb9f05ca3c963743754a6f719907818e0c4c609 100644 (file)
@@ -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, ...
index 7195c9d48d767b538574b0b5ab607e890cc6dc58..bb1e239c3490c10d9555c0c2e60a49965f7313d6 100644 (file)
@@ -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)
   {