diff mbox series

C++: add type checking for static local vector variable in template

Message ID 20210901081159.4747-1-pc.wang@linux.alibaba.com
State New
Headers show
Series C++: add type checking for static local vector variable in template | expand

Commit Message

pc.wang Sept. 1, 2021, 8:11 a.m. UTC
From: wangpc <wpc337719@alibaba-inc.com>

---
 gcc/cp/pt.c                                    |  8 +++++++-
 .../aarch64/sve/static-var-in-template.C       | 18 ++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.target/aarch64/sve/static-var-in-template.C
diff mbox series

Patch

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index f0aa626ab723..988f4cb1e73f 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -14731,7 +14731,13 @@  tsubst_decl (tree t, tree args, tsubst_flags_t complain)
 		 even if its underlying type is not.  */
 	      TYPE_DEPENDENT_P_VALID (TREE_TYPE (r)) = false;
 	  }
-
+    /* We should verify static local variable's type
+    since vector type does not have a fixed size.  */
+    if (TREE_STATIC (t)
+      &&!verify_type_context (input_location, TCTX_STATIC_STORAGE, type))
+    {
+      RETURN (error_mark_node);
+    }
 	layout_decl (r, 0);
       }
       break;
diff --git a/gcc/testsuite/g++.target/aarch64/sve/static-var-in-template.C b/gcc/testsuite/g++.target/aarch64/sve/static-var-in-template.C
new file mode 100644
index 000000000000..26d397ca565d
--- /dev/null
+++ b/gcc/testsuite/g++.target/aarch64/sve/static-var-in-template.C
@@ -0,0 +1,18 @@ 
+/* { dg-do compile } */
+
+#include <arm_sve.h>
+
+template <int N>
+void f()
+{
+    int i = 0;
+    static svbool_t pg = svwhilelt_b64(0, N);
+}
+
+int main(int argc, char **argv)
+{
+    f<2>();
+    return 0;
+}
+
+/* { dg-error {SVE type 'svbool_t' does not have a fixed size} } */