From: Douglas Gregor Date: Fri, 15 Jan 2010 16:21:02 +0000 (+0000) Subject: When determining whether a DeclRefExpr is value-dependent when it X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=501edb6a54524555ad27fbf41a7920dc756b08c6;p=clang When determining whether a DeclRefExpr is value-dependent when it references a const variable of integral type, the initializer may be in a different declaration than the one that name-lookup saw. Find the initializer anyway. Fixes PR6045. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@93514 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 4c3046bed1..fa44b510e9 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -98,10 +98,12 @@ void DeclRefExpr::computeDependence() { // initialized with an expression that is value-dependent. else if (VarDecl *Var = dyn_cast(D)) { if (Var->getType()->isIntegralType() && - Var->getType().getCVRQualifiers() == Qualifiers::Const && - Var->getInit() && - Var->getInit()->isValueDependent()) - ValueDependent = true; + Var->getType().getCVRQualifiers() == Qualifiers::Const) { + const VarDecl *Def = 0; + if (const Expr *Init = Var->getDefinition(Def)) + if (Init->isValueDependent()) + ValueDependent = true; + } } // (TD) - a nested-name-specifier or a qualified-id that names a // member of an unknown specialization. diff --git a/test/SemaTemplate/dependent-expr.cpp b/test/SemaTemplate/dependent-expr.cpp index 412a811f72..3f481b5136 100644 --- a/test/SemaTemplate/dependent-expr.cpp +++ b/test/SemaTemplate/dependent-expr.cpp @@ -5,3 +5,22 @@ template void Test(Iterator it) { *(it += 1); } + +namespace PR6045 { + template + class A + { + static const unsigned int member = r; + void f(); + }; + + template + const unsigned int A::member; + + template + void A::f() + { + unsigned k; + (void)(k % member); + } +}