diff --git a/clang/lib/Sema/SemaCUDA.cpp b/clang/lib/Sema/SemaCUDA.cpp index ec37c0df56c67..6fe10e41e3d9f 100644 --- a/clang/lib/Sema/SemaCUDA.cpp +++ b/clang/lib/Sema/SemaCUDA.cpp @@ -659,9 +659,9 @@ void SemaCUDA::checkAllowedInitializer(VarDecl *VD) { // Return early if VD is inside a non-instantiated template function since // the implicit constructor is not defined yet. if (const FunctionDecl *FD = - dyn_cast_or_null(VD->getDeclContext())) - if (FD->isDependentContext()) - return; + dyn_cast_or_null(VD->getDeclContext()); + FD && FD->isDependentContext()) + return; // Do not check dependent variables since the ctor/dtor/initializer are not // determined. Do it after instantiation.