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 r13-2696] c++: member fn in omp loc list [PR106858] Date: Fri, 16 Sep 2022 12:44:05 +0000 (GMT) [thread overview] Message-ID: <20220916124405.CA4E23853805@sourceware.org> (raw) https://gcc.gnu.org/g:39dc66558e066e67fd40f21f53cee80989ae742d commit r13-2696-g39dc66558e066e67fd40f21f53cee80989ae742d Author: Jason Merrill <jason@redhat.com> Date: Thu Sep 15 22:55:50 2022 +0200 c++: member fn in omp loc list [PR106858] this-f names a member function, which isn't an addressable lvalue. Give a helpful error instead of crashing. The first hunk makes the error range cover the whole expression. PR c++/106858 gcc/cp/ChangeLog: * parser.cc (cp_parser_omp_var_list_no_open): Pass the initial token location down. * semantics.cc (finish_omp_clauses): Check invalid_nonstatic_memfn_p. * typeck.cc (invalid_nonstatic_memfn_p): Handle null TREE_TYPE. gcc/testsuite/ChangeLog: * g++.dg/gomp/map-3.C: New test. Diff: --- gcc/cp/parser.cc | 7 +++---- gcc/cp/semantics.cc | 4 ++++ gcc/cp/typeck.cc | 3 ++- gcc/testsuite/g++.dg/gomp/map-3.C | 9 +++++++++ 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 841ba6ed997..3cbe0d69de1 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -36938,10 +36938,9 @@ cp_parser_omp_var_list_no_open (cp_parser *parser, enum omp_clause_code kind, cp_id_kind idk = CP_ID_KIND_NONE; cp_lexer_consume_token (parser->lexer); decl = convert_from_reference (decl); - decl - = cp_parser_postfix_dot_deref_expression (parser, ttype, - decl, false, - &idk, loc); + decl = (cp_parser_postfix_dot_deref_expression + (parser, ttype, cp_expr (decl, token->location), + false, &idk, loc)); } /* FALLTHROUGH. */ case OMP_CLAUSE_AFFINITY: diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 427b1ab5ebc..86562071612 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -8119,6 +8119,10 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type ort) t = TREE_OPERAND (t, 1); STRIP_NOPS (t); } + if (TREE_CODE (t) == COMPONENT_REF + && invalid_nonstatic_memfn_p (EXPR_LOCATION (t), t, + tf_warning_or_error)) + remove = true; indir_component_ref_p = false; if (TREE_CODE (t) == COMPONENT_REF && (TREE_CODE (TREE_OPERAND (t, 0)) == INDIRECT_REF diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc index 3e461d5cdcb..22d834d3a58 100644 --- a/gcc/cp/typeck.cc +++ b/gcc/cp/typeck.cc @@ -2196,7 +2196,8 @@ invalid_nonstatic_memfn_p (location_t loc, tree expr, tsubst_flags_t complain) return false; if (is_overloaded_fn (expr) && !really_overloaded_fn (expr)) expr = get_first_fn (expr); - if (DECL_NONSTATIC_MEMBER_FUNCTION_P (expr)) + if (TREE_TYPE (expr) + && DECL_NONSTATIC_MEMBER_FUNCTION_P (expr)) { if (complain & tf_error) { diff --git a/gcc/testsuite/g++.dg/gomp/map-3.C b/gcc/testsuite/g++.dg/gomp/map-3.C new file mode 100644 index 00000000000..c45f8509521 --- /dev/null +++ b/gcc/testsuite/g++.dg/gomp/map-3.C @@ -0,0 +1,9 @@ +// PR c++/106858 +// { dg-additional-options "-fopenmp -fsanitize=undefined" } + +class A { + void f() { + #pragma omp target map(this->f) // { dg-error "member function" } + ; + } +};
reply other threads:[~2022-09-16 12:44 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=20220916124405.CA4E23853805@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).