diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp
index ed0b9a530..6cfcaf93c 100644
--- a/lib/tokenize.cpp
+++ b/lib/tokenize.cpp
@@ -4013,7 +4013,8 @@ void Tokenizer::setVarIdPass1()
                     if (tok && tok->str() == "<") {
                         const Token *end = tok->findClosingBracket();
                         while (tok != end) {
-                            if (tok->isName()) {
+                            if (tok->isName() && !(Token::simpleMatch(tok->next(), "<") &&
+                                                   Token::Match(tok->tokAt(-2), "std :: %name%"))) {
                                 const std::map<std::string, int>::const_iterator it = variableMap.find(tok->str());
                                 if (it != variableMap.end())
                                     tok->varId(it->second);
diff --git a/test/testother.cpp b/test/testother.cpp
index 4b14e7cc0..df55ca7b4 100644
--- a/test/testother.cpp
+++ b/test/testother.cpp
@@ -4589,6 +4589,11 @@ private:
               "    for (p = path; *p++;) ;\n"
               "}");
         ASSERT_EQUALS("", errout.str());
+
+        check("void f() {\n"
+              "    std::array<std::array<double,3>,3> array;\n"
+              "}\n");
+        ASSERT_EQUALS("", errout.str());
     }
 
     void duplicateBranch() {
diff --git a/test/testunusedfunctions.cpp b/test/testunusedfunctions.cpp
index 7fb54c417..678b720f4 100644
--- a/test/testunusedfunctions.cpp
+++ b/test/testunusedfunctions.cpp
@@ -47,6 +47,7 @@ private:
         TEST_CASE(template4); // #9805
         TEST_CASE(template5);
         TEST_CASE(template6); // #10475 crash
+        TEST_CASE(template7); // #9766 crash
         TEST_CASE(throwIsNotAFunction);
         TEST_CASE(unusedError);
         TEST_CASE(unusedMain);
@@ -268,6 +269,14 @@ private:
         ASSERT_EQUALS("", errout.str());
     }
 
+    void template7()
+    { // #9766
+        check("void f() {\n"
+              "    std::array<std::array<double,3>,3> array;\n"
+              "}\n");
+        ASSERT_EQUALS("[test.cpp:1]: (style) The function 'f' is never used.\n", errout.str());
+    }
+
     void throwIsNotAFunction() {
         check("struct A {void f() const throw () {}}; int main() {A a; a.f();}");
         ASSERT_EQUALS("", errout.str());