public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Jason Merrill <jason@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-3720] C++: add type checking for static local vector variable in template Date: Tue, 21 Sep 2021 00:53:05 +0000 (GMT) [thread overview] Message-ID: <20210921005305.36DDD3858D3C@sourceware.org> (raw) https://gcc.gnu.org/g:56c24f18cce0da6405c5071b838844447fa81ac8 commit r12-3720-g56c24f18cce0da6405c5071b838844447fa81ac8 Author: wangpc <pc.wang@linux.alibaba.com> Date: Sat Sep 18 13:53:09 2021 +0800 C++: add type checking for static local vector variable in template This patch moves verify_type_context from start_decl_1 to cp_finish_decl to do more type checking such as static local vector variable in C++ template. 2021-08-06 wangpc <pc.wang@linux.alibaba.com> gcc/cp/ChangeLog * decl.c (start_decl_1): Move verify_type_context to ... (cp_finish_decl): ... to here. gcc/testsuite/ChangeLog * g++.target/aarch64/sve/static-var-in-template.C: New test. Diff: --- gcc/cp/decl.c | 16 ++++++++-------- .../g++.target/aarch64/sve/static-var-in-template.C | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 58ddc6a537e..722e540baba 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -5772,14 +5772,6 @@ start_decl_1 (tree decl, bool initialized) cp_apply_type_quals_to_decl (cp_type_quals (type), decl); } - if (is_global_var (decl)) - { - type_context_kind context = (DECL_THREAD_LOCAL_P (decl) - ? TCTX_THREAD_STORAGE - : TCTX_STATIC_STORAGE); - verify_type_context (input_location, context, TREE_TYPE (decl)); - } - if (initialized) /* Is it valid for this decl to have an initializer at all? */ { @@ -7977,6 +7969,14 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, && DECL_INITIALIZED_IN_CLASS_P (decl)) check_static_variable_definition (decl, type); + if (!processing_template_decl && VAR_P (decl) && is_global_var (decl)) + { + type_context_kind context = (DECL_THREAD_LOCAL_P (decl) + ? TCTX_THREAD_STORAGE + : TCTX_STATIC_STORAGE); + verify_type_context (input_location, context, TREE_TYPE (decl)); + } + if (init && TREE_CODE (decl) == FUNCTION_DECL) { tree clone; 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 00000000000..74237ff7c57 --- /dev/null +++ b/gcc/testsuite/g++.target/aarch64/sve/static-var-in-template.C @@ -0,0 +1,17 @@ +/* { dg-do compile } */ + +#include <arm_sve.h> + +template <int N> +void f() +{ + 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" "" { target *-*-* } 0 } */
reply other threads:[~2021-09-21 0:53 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210921005305.36DDD3858D3C@sourceware.org \ --to=jason@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).