aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/semantics.c
AgeCommit message (Collapse)AuthorFilesLines
2021-04-02c++: Refine check for CTAD placeholder [PR99586]Patrick Palka1-8/+7
In the below testcase, during finish_compound_literal for A<B{V}>{}, type_uses_auto finds and returns the CTAD placeholder for B{V}, which tricks us into attempting CTAD on A<B{V}>{} and leads to bogus errors. AFAICT 'type' will always be a bare 'auto' in the CTAD case so we don't need to look deeply to find it; checking template_placeholder_p instead should suffice here. gcc/cp/ChangeLog: PR c++/99586 * semantics.c (finish_compound_literal): Check template_placeholder_p instead of type_uses_auto. gcc/testsuite/ChangeLog: PR c++/99586 * g++.dg/cpp2a/nontype-class42.C: New test.
2021-03-17c++: Private parent access check for using decls [PR19377]Anthony Sharp1-18/+83
This bug was already mostly fixed by the patch for PR17314. This patch continues that by ensuring that where a using decl is used, causing an access failure to a child class because the using decl is private, the compiler correctly points to the using decl as the source of the problem. gcc/cp/ChangeLog: 2021-03-10 Anthony Sharp <anthonysharp15@gmail.com> * semantics.c (get_class_access_diagnostic_decl): New function that examines special cases when a parent class causes a private access failure. (enforce_access): Slightly modified to call function above. gcc/testsuite/ChangeLog: 2021-03-10 Anthony Sharp <anthonysharp15@gmail.com> * g++.dg/cpp1z/using9.C: New using decl test. Co-authored-by: Jason Merrill <jason@redhat.com>
2021-02-11c++: ICE with unexpanded pack in do-while [PR99063]Marek Polacek1-0/+5
Here an unexpanded parameter pack snuck into prep_operand which doesn't expect to see an operand without a type, and since r247842 NONTYPE_ARGUMENT_PACK doesn't have a type anymore. This only happens with the do-while loop whose condition may not contain a declaration so we never called finish_cond which checks for unexpanded parameter packs. So use check_for_bare_parameter_packs to remedy that. gcc/cp/ChangeLog: PR c++/99063 * semantics.c (finish_do_stmt): Check for unexpanded parameter packs. gcc/testsuite/ChangeLog: PR c++/99063 * g++.dg/cpp0x/variadic-crash6.C: New test.
2021-01-23c++: private inheritance access diagnostics fix [PR17314]Anthony Sharp1-1/+30
This patch fixes PR17314. Previously, when class C attempted to access member a declared in class A through class B, where class B privately inherits from A and class C inherits from B, GCC would correctly report an access violation, but would erroneously report that the reason was because a was "protected", when in fact, from the point of view of class C, it was really "private". This patch updates the diagnostics code to generate more correct errors in cases of failed inheritance such as these. The reason this bug happened was because GCC was examining the declared access of decl, instead of looking at it in the context of class inheritance. gcc/cp/ChangeLog: 2021-01-21 Anthony Sharp <anthonysharp15@gmail.com> * call.c (complain_about_access): Altered function. * cp-tree.h (complain_about_access): Changed parameters of function. (get_parent_with_private_access): Declared new function. * search.c (get_parent_with_private_access): Defined new function. * semantics.c (enforce_access): Modified function. * typeck.c (complain_about_unrecognized_member): Updated function arguments in complain_about_access. gcc/testsuite/ChangeLog: 2021-01-21 Anthony Sharp <anthonysharp15@gmail.com> * g++.dg/lookup/scoped1.C: Modified testcase to run successfully with changes. * g++.dg/tc1/dr142.C: Same as above. * g++.dg/tc1/dr52.C: Same as above. * g++.old-deja/g++.brendan/visibility6.C: Same as above. * g++.old-deja/g++.brendan/visibility8.C: Same as above. * g++.old-deja/g++.jason/access8.C: Same as above. * g++.old-deja/g++.law/access4.C: Same as above. * g++.old-deja/g++.law/visibility12.C: Same as above. * g++.old-deja/g++.law/visibility4.C: Same as above. * g++.old-deja/g++.law/visibility8.C: Same as above. * g++.old-deja/g++.other/access4.C: Same as above.
2021-01-23c++: 'this' injection and static member functions [PR97399]Patrick Palka1-2/+1
In the testcase pr97399.C below, finish_qualified_id_expr at parse time adds an implicit 'this->' to the expression tmp::integral<T> (because it's type-dependent, and also current_class_ptr is set at this point) within the trailing return type. Later when substituting into this trailing return type we crash because we can't resolve the 'this', since tsubst_function_type does inject_this_parm only for non-static member functions, which tmp::func is not. This patch fixes this issue by removing the type-dependence check in finish_qualified_id_expr added by r9-5972, and instead relaxes shared_member_p to handle dependent USING_DECLs: > I think I was wrong in my assertion around Alex's patch that > shared_member_p should abort on a dependent USING_DECL; it now seems > appropriate for it to return false if we don't know, we just need to > adjust the comment to say that. And when parsing a friend function declaration, we shouldn't be setting current_class_ptr at all, so this patch additionally suppresses inject_this_parm in this case. Finally, the self-contained change to cp_parser_init_declarator is so that we properly communicate static-ness to cp_parser_direct_declarator when parsing a member function template. This lets us reject the explicit use of 'this' in the testcase this2.C below. gcc/cp/ChangeLog: PR c++/97399 * cp-tree.h (shared_member_p): Adjust declaration. * parser.c (cp_parser_init_declarator): If the storage class specifier is sc_static, pass true for static_p to cp_parser_declarator. (cp_parser_direct_declarator): Don't do inject_this_parm when the declarator is a friend. * search.c (shared_member_p): Change return type to bool and adjust function body accordingly. Return false for a dependent USING_DECL instead of aborting. * semantics.c (finish_qualified_id_expr): Rely on shared_member_p even when type-dependent. gcc/testsuite/ChangeLog: PR c++/88548 PR c++/97399 * g++.dg/cpp0x/this2.C: New test. * g++.dg/template/pr97399.C: New test.
2021-01-21c++: Fix excessive instantiation inside decltype [PR71879]Patrick Palka1-2/+3
Here after resolving the address of a template-id inside decltype, we end up instantiating the chosen specialization (from the call to mark_used in resolve_nondeduced_context), even though only its type is needed. This patch sets cp_unevaluated_operand throughout finish_decltype_type, so that in particular it's set during the call to resolve_nondeduced_context within. gcc/cp/ChangeLog: PR c++/71879 * semantics.c (finish_decltype_type): Set up a cp_unevaluated sentinel at the start of the function. Remove a now-redundant manual adjustment of cp_unevaluated_operand. gcc/testsuite/ChangeLog: PR c++/71879 * g++.dg/cpp0x/decltype-71879.C: New test.
2021-01-20openmp: Don't ICE on detach clause with erroneous decl [PR98742]Jakub Jelinek1-0/+6
Similarly to how we handle erroneous operands to e.g. allocate clause, this change just removes those clauses instead of accessing TYPE_MAIN_VARIANT of its type, which doesn't work on error_mark_node. Also, just for good measure, bails out if TYPE_NAME is NULL. 2021-01-20 Jakub Jelinek <jakub@redhat.com> PR c++/98742 * semantics.c (finish_omp_clauses) <case OMP_CLAUSE_DETACH>: If error_operand_p, remove clause without further checking. Check for non-NULL TYPE_NAME. * c-c++-common/gomp/task-detach-2.c: New test.
2021-01-16openmp: Add support for the OpenMP 5.0 task detach clauseKwok Cheung Yeung1-1/+60
2021-01-16 Kwok Cheung Yeung <kcy@codesourcery.com> gcc/ * builtin-types.def (BT_FN_VOID_OMPFN_PTR_OMPCPYFN_LONG_LONG_BOOL_UINT_PTR_INT): Rename to... (BT_FN_VOID_OMPFN_PTR_OMPCPYFN_LONG_LONG_BOOL_UINT_PTR_INT_PTR): ...this. Add extra argument. * gimplify.c (omp_default_clause): Ensure that event handle is firstprivate in a task region. (gimplify_scan_omp_clauses): Handle OMP_CLAUSE_DETACH. (gimplify_adjust_omp_clauses): Likewise. * omp-builtins.def (BUILT_IN_GOMP_TASK): Change function type to BT_FN_VOID_OMPFN_PTR_OMPCPYFN_LONG_LONG_BOOL_UINT_PTR_INT_PTR. * omp-expand.c (expand_task_call): Add GOMP_TASK_FLAG_DETACH to flags if detach clause specified. Add detach argument when generating call to GOMP_task. * omp-low.c (scan_sharing_clauses): Setup data environment for detach clause. (finish_taskreg_scan): Move field for variable containing the event handle to the front of the struct. * tree-core.h (enum omp_clause_code): Add OMP_CLAUSE_DETACH. Fix ordering. * tree-nested.c (convert_nonlocal_omp_clauses): Handle OMP_CLAUSE_DETACH clause. (convert_local_omp_clauses): Handle OMP_CLAUSE_DETACH clause. * tree-pretty-print.c (dump_omp_clause): Handle OMP_CLAUSE_DETACH. * tree.c (omp_clause_num_ops): Add entry for OMP_CLAUSE_DETACH. Fix ordering. (omp_clause_code_name): Add entry for OMP_CLAUSE_DETACH. Fix ordering. (walk_tree_1): Handle OMP_CLAUSE_DETACH. gcc/c-family/ * c-pragma.h (pragma_omp_clause): Add PRAGMA_OMP_CLAUSE_DETACH. Redefine PRAGMA_OACC_CLAUSE_DETACH. gcc/c/ * c-parser.c (c_parser_omp_clause_detach): New. (c_parser_omp_all_clauses): Handle PRAGMA_OMP_CLAUSE_DETACH clause. (OMP_TASK_CLAUSE_MASK): Add mask for PRAGMA_OMP_CLAUSE_DETACH. * c-typeck.c (c_finish_omp_clauses): Handle PRAGMA_OMP_CLAUSE_DETACH clause. Prevent use of detach with mergeable and overriding the data sharing mode of the event handle. gcc/cp/ * parser.c (cp_parser_omp_clause_detach): New. (cp_parser_omp_all_clauses): Handle PRAGMA_OMP_CLAUSE_DETACH. (OMP_TASK_CLAUSE_MASK): Add mask for PRAGMA_OMP_CLAUSE_DETACH. * pt.c (tsubst_omp_clauses): Handle OMP_CLAUSE_DETACH clause. * semantics.c (finish_omp_clauses): Handle OMP_CLAUSE_DETACH clause. Prevent use of detach with mergeable and overriding the data sharing mode of the event handle. gcc/fortran/ * dump-parse-tree.c (show_omp_clauses): Handle detach clause. * frontend-passes.c (gfc_code_walker): Walk detach expression. * gfortran.h (struct gfc_omp_clauses): Add detach field. (gfc_c_intptr_kind): New. * openmp.c (gfc_free_omp_clauses): Free detach clause. (gfc_match_omp_detach): New. (enum omp_mask1): Add OMP_CLAUSE_DETACH. (enum omp_mask2): Remove OMP_CLAUSE_DETACH. (gfc_match_omp_clauses): Handle OMP_CLAUSE_DETACH for OpenMP. (OMP_TASK_CLAUSES): Add OMP_CLAUSE_DETACH. (resolve_omp_clauses): Prevent use of detach with mergeable and overriding the data sharing mode of the event handle. * trans-openmp.c (gfc_trans_omp_clauses): Handle detach clause. * trans-types.c (gfc_c_intptr_kind): New. (gfc_init_kinds): Initialize gfc_c_intptr_kind. * types.def (BT_FN_VOID_OMPFN_PTR_OMPCPYFN_LONG_LONG_BOOL_UINT_PTR_INT): Rename to... (BT_FN_VOID_OMPFN_PTR_OMPCPYFN_LONG_LONG_BOOL_UINT_PTR_INT_PTR): ...this. Add extra argument. gcc/testsuite/ * c-c++-common/gomp/task-detach-1.c: New. * g++.dg/gomp/task-detach-1.C: New. * gcc.dg/gomp/task-detach-1.c: New. * gfortran.dg/gomp/task-detach-1.f90: New. include/ * gomp-constants.h (GOMP_TASK_FLAG_DETACH): New. libgomp/ * fortran.c (omp_fulfill_event_): New. * libgomp.h (struct gomp_task): Add detach and completion_sem fields. (struct gomp_team): Add task_detach_queue and task_detach_count fields. * libgomp.map (OMP_5.0.1): Add omp_fulfill_event and omp_fulfill_event_. * libgomp_g.h (GOMP_task): Add extra argument. * omp.h.in (enum omp_event_handle_t): New. (omp_fulfill_event): New. * omp_lib.f90.in (omp_event_handle_kind): New. (omp_fulfill_event): New. * omp_lib.h.in (omp_event_handle_kind): New. (omp_fulfill_event): Declare. * priority_queue.c (priority_tree_find): New. (priority_list_find): New. (priority_queue_find): New. * priority_queue.h (priority_queue_predicate): New. (priority_queue_find): New. * task.c (gomp_init_task): Initialize detach field. (task_fulfilled_p): New. (GOMP_task): Add detach argument. Ignore detach argument if GOMP_TASK_FLAG_DETACH not set in flags. Initialize completion_sem field. Copy address of completion_sem into detach argument and into the start of the data record. Wait for detach event if task not deferred. (gomp_barrier_handle_tasks): Queue tasks with unfulfilled events. Remove completed tasks and requeue dependent tasks. (omp_fulfill_event): New. * team.c (gomp_new_team): Initialize task_detach_queue and task_detach_count fields. (free_team): Free task_detach_queue field. * testsuite/libgomp.c-c++-common/task-detach-1.c: New testcase. * testsuite/libgomp.c-c++-common/task-detach-2.c: New testcase. * testsuite/libgomp.c-c++-common/task-detach-3.c: New testcase. * testsuite/libgomp.c-c++-common/task-detach-4.c: New testcase. * testsuite/libgomp.c-c++-common/task-detach-5.c: New testcase. * testsuite/libgomp.c-c++-common/task-detach-6.c: New testcase. * testsuite/libgomp.fortran/task-detach-1.f90: New testcase. * testsuite/libgomp.fortran/task-detach-2.f90: New testcase. * testsuite/libgomp.fortran/task-detach-3.f90: New testcase. * testsuite/libgomp.fortran/task-detach-4.f90: New testcase. * testsuite/libgomp.fortran/task-detach-5.f90: New testcase. * testsuite/libgomp.fortran/task-detach-6.f90: New testcase.
2021-01-08c++: Fix access checking of scoped non-static member [PR98515]Patrick Palka1-5/+15
In the first testcase below, we incorrectly reject the use of the protected non-static member A::var0 from C<int>::g() because check_accessibility_of_qualified_id, at template parse time, determines that the access doesn't go through 'this'. (This happens because the dependent base B<T> of C<T> doesn't have a binfo object, so it appears to DERIVED_FROM_P that A is not an indirect base of C<T>.) From there we create the corresponding deferred access check, which we then perform at instantiation time and which (expectedly) fails. The problem ultimately seems to be that we can't in general determine whether a use of a scoped non-static member goes through 'this' until instantiation time, as the second testcase below illustrates. So this patch makes check_accessibility_of_qualified_id punt in such situations to avoid creating a bogus deferred access check. gcc/cp/ChangeLog: PR c++/98515 * semantics.c (check_accessibility_of_qualified_id): Punt if we're checking access of a scoped non-static member inside a class template. gcc/testsuite/ChangeLog: PR c++/98515 * g++.dg/template/access32.C: New test. * g++.dg/template/access33.C: New test.
2021-01-05c++: Fix ICE with __builtin_bit_cast [PR98469]Jakub Jelinek1-0/+4
On the following testcase we ICE during constexpr evaluation (for warnings), because the IL has ADDR_EXPR of BIT_CAST_EXPR and ADDR_EXPR case asserts the result is not a CONSTRUCTOR. The patch punts on lval BIT_CAST_EXPR folding. > This change is OK, but part of the problem is that we're trying to do > overload resolution for an S copy/move constructor, which we shouldn't be > because bit_cast is a prvalue, so in C++17 and up we should use it to > directly initialize the target without any implied constructor call. This version therefore wraps it into a TARGET_EXPR then, it alone fixes the bug, but I've kept the constexpr.c change too. 2021-01-05 Jakub Jelinek <jakub@redhat.com> PR c++/98469 * constexpr.c (cxx_eval_constant_expression) <case BIT_CAST_EXPR>: Punt if lval is true. * semantics.c (cp_build_bit_cast): Call get_target_expr_sfinae on the result if it has a class type. * g++.dg/cpp2a/bit-cast8.C: New test. * g++.dg/cpp2a/bit-cast9.C: New test.
2021-01-04Update copyright years.Jakub Jelinek1-1/+1
2020-12-09c++: Decl module-specific semantic processingNathan Sidwell1-1/+15
This adds the module-specific logic to the various declaration processing routines in decl.c and semantic.c. I also adjust the rtti type creation, as those are all in the global module, so we need to temporarily clear the module_kind, when they are being created. Finally, I added init and fini module processing with the initialier giving a fatal error if you try and turn it on (so don't do that yet). gcc/cp/ * decl.c (duplicate_decls): Add module-specific redeclaration logic. (cxx_init_decl_processing): Export the global namespace, maybe initialize modules. (start_decl): Reject local-extern in a module, adjust linkage of template var. (xref_tag_1): Add module-specific redeclaration logic. (start_enum): Likewise. (finish_enum_value_list): Export unscoped members of an exported enum. (grokmethod): Implement p1779 linkage of in-class defined functions. * decl2.c (no_linkage_error): Imports are ok. (c_parse_final_cleanups): Call fini_modules. * lex.c (cxx_dup_lang_specific): Clear some module flags in the copy. * module.cc (module_kind): Define. (module_may_redeclare, set_defining_module): Stubs. (init_modules): Error on modules. (fini_modules): Stub. * rtti.c (push_abi_namespace): Save and reset module_kind. (pop_abi_namespace): Restore module kind. (build_dynamic_cast_1, tinfo_base_init): Adjust. * semantics.c (begin_class_definition): Add module-specific logic. (expand_or_defer_fn_1): Keep bodies of more fns when modules_p.
2020-12-03c++: Add __builtin_bit_cast to implement std::bit_cast [PR93121]Jakub Jelinek1-0/+71
The following patch adds __builtin_bit_cast builtin, similarly to clang or MSVC which implement std::bit_cast using such an builtin too. It checks the various std::bit_cast requirements, when not constexpr evaluated acts pretty much like VIEW_CONVERT_EXPR of the source argument to the destination type and the hardest part is obviously the constexpr evaluation. I've left out PDP11 handling of those, couldn't figure out how exactly are bitfields laid out there 2020-12-03 Jakub Jelinek <jakub@redhat.com> PR libstdc++/93121 * fold-const.h (native_encode_initializer): Add mask argument defaulted to nullptr. (find_bitfield_repr_type): Declare. (native_interpret_aggregate): Declare. * fold-const.c (find_bitfield_repr_type): New function. (native_encode_initializer): Add mask argument and support for filling it. Handle also some bitfields without integral DECL_BIT_FIELD_REPRESENTATIVE. (native_interpret_aggregate): New function. * gimple-fold.h (clear_type_padding_in_mask): Declare. * gimple-fold.c (struct clear_padding_struct): Add clear_in_mask member. (clear_padding_flush): Handle buf->clear_in_mask. (clear_padding_union): Copy clear_in_mask. Don't error if buf->clear_in_mask is set. (clear_padding_type): Don't error if buf->clear_in_mask is set. (clear_type_padding_in_mask): New function. (gimple_fold_builtin_clear_padding): Set buf.clear_in_mask to false. * doc/extend.texi (__builtin_bit_cast): Document. * c-common.h (enum rid): Add RID_BUILTIN_BIT_CAST. * c-common.c (c_common_reswords): Add __builtin_bit_cast. * cp-tree.h (cp_build_bit_cast): Declare. * cp-tree.def (BIT_CAST_EXPR): New tree code. * cp-objcp-common.c (names_builtin_p): Handle RID_BUILTIN_BIT_CAST. (cp_common_init_ts): Handle BIT_CAST_EXPR. * cxx-pretty-print.c (cxx_pretty_printer::postfix_expression): Likewise. * parser.c (cp_parser_postfix_expression): Handle RID_BUILTIN_BIT_CAST. * semantics.c (cp_build_bit_cast): New function. * tree.c (cp_tree_equal): Handle BIT_CAST_EXPR. (cp_walk_subtrees): Likewise. * pt.c (tsubst_copy): Likewise. * constexpr.c (check_bit_cast_type, cxx_eval_bit_cast): New functions. (cxx_eval_constant_expression): Handle BIT_CAST_EXPR. (potential_constant_expression_1): Likewise. * cp-gimplify.c (cp_genericize_r): Likewise. * g++.dg/cpp2a/bit-cast1.C: New test. * g++.dg/cpp2a/bit-cast2.C: New test. * g++.dg/cpp2a/bit-cast3.C: New test. * g++.dg/cpp2a/bit-cast4.C: New test. * g++.dg/cpp2a/bit-cast5.C: New test.
2020-11-13c++: Implement C++20 'using enum'. [PR91367]Jason Merrill1-3/+11
This feature allows the programmer to import enumerator names into the current scope so later mentions don't need to use the fully-qualified name. These usings are not subject to the usual restrictions on using-decls: in particular, they can move between class and non-class scopes, and between classes that are not related by inheritance. This last caused difficulty for our normal approach to using-decls within a class hierarchy, as we assume that the class where we looked up a used declaration is derived from the class where it was first declared. So to simplify things, in that case we make a clone of the CONST_DECL in the using class. Thanks to Nathan for the start of this work: in particular, the lookup_using_decl rewrite. The changes to dwarf2out revealed an existing issue with the D front-end: we were doing the wrong thing for importing a D CONST_DECL, because dwarf2out_imported_module_or_decl_1 was looking through it to its type, expecting it to be an enumerator, but in one case in thread.d, the constant had type int. Adding the ability to import a C++ enumerator also fixed that, but that led to a crash in force_decl_die, which didn't know what to do with a CONST_DECL. So now it does. Co-authored-by: Nathan Sidwell <nathan@acm.org> gcc/cp/ChangeLog: * cp-tree.h (USING_DECL_UNRELATED_P): New. (CONST_DECL_USING_P): New. * class.c (handle_using_decl): If USING_DECL_UNRELATED_P, clone the CONST_DECL. * name-lookup.c (supplement_binding_1): A clone hides its using-declaration. (lookup_using_decl): Rewrite to separate lookup and validation. (do_class_using_decl): Adjust. (finish_nonmember_using_decl): Adjust. * parser.c (make_location): Add cp_token overload. (finish_using_decl): Split out from... (cp_parser_using_declaration): ...here. Don't look through enums. (cp_parser_using_enum): New. (cp_parser_block_declaration): Call it. (cp_parser_member_declaration): Call it. * semantics.c (finish_id_expression_1): Handle enumerator used from class scope. gcc/ChangeLog: * dwarf2out.c (gen_enumeration_type_die): Call equate_decl_number_to_die for enumerators. (gen_member_die): Don't move enumerators to their enclosing class. (dwarf2out_imported_module_or_decl_1): Allow importing individual enumerators. (force_decl_die): Handle CONST_DECL. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/inh-ctor28.C: Adjust expected diagnostic. * g++.dg/cpp0x/inh-ctor33.C: Likewise. * g++.dg/cpp0x/using-enum-1.C: Add comment. * g++.dg/cpp0x/using-enum-2.C: Allowed in C++20. * g++.dg/cpp0x/using-enum-3.C: Likewise. * g++.dg/cpp1z/class-deduction69.C: Adjust diagnostic. * g++.dg/inherit/using5.C: Likewise. * g++.dg/cpp2a/using-enum-1.C: New test. * g++.dg/cpp2a/using-enum-2.C: New test. * g++.dg/cpp2a/using-enum-3.C: New test. * g++.dg/cpp2a/using-enum-4.C: New test. * g++.dg/cpp2a/using-enum-5.C: New test. * g++.dg/cpp2a/using-enum-6.C: New test. * g++.dg/debug/dwarf2/using-enum.C: New test.
2020-11-12c++: Don't form a templated TARGET_EXPR in finish_compound_literalPatrick Palka1-6/+1
The atom_cache in normalize_atom relies on the assumption that two equivalent (templated) trees (in the sense of cp_tree_equal) must use the same template parameters (according to find_template_parameters). This assumption unfortunately doesn't always hold for TARGET_EXPRs, because cp_tree_equal ignores an artificial target of a TARGET_EXPR, but find_template_parameters walks this target (and its DECL_CONTEXT). Hence two TARGET_EXPRs built by force_target_expr with the same initializer and under different settings of current_function_decl will compare equal according to cp_tree_equal, but find_template_parameters may return a different set of template parameters for them. This breaks the below testcase because during normalization we build two such TARGET_EXPRs (one under current_function_decl=f and another under =g), and then share the same ATOMIC_CONSTR for the two corresponding atoms, leading to a crash during satisfaction of g's associated constraints. This patch works around this issue by removing the source of these templated TARGET_EXPRs. The relevant call to get_target_expr_sfinae was added in r9-6043, and it seems it's no longer necessary (according to https://gcc.gnu.org/pipermail/gcc-patches/2019-February/517323.html, the call was added in order to avoid regressing on initlist109.C at the time). gcc/cp/ChangeLog: * semantics.c (finish_compound_literal): Don't wrap the original compound literal in a TARGET_EXPR when inside a template. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-decltype3.C: New test.
2020-11-10c++: Improve static_assert diagnostic [PR97518]Marek Polacek1-12/+61
Currently, when a static_assert fails, we only say "static assertion failed". It would be more useful if we could also print the expression that evaluated to false; this is especially useful when the condition uses template parameters. Consider the motivating example, in which we have this line: static_assert(is_same<X, Y>::value); if this fails, the user has to play dirty games to get the compiler to print the template arguments. With this patch, we say: error: static assertion failed note: 'is_same<int*, int>::value' evaluates to false which I think is much better. However, always printing the condition that evaluated to 'false' wouldn't be very useful: e.g. noexcept(fn) is always parsed to true/false, so we would say "'false' evaluates to false" which doesn't help. So I wound up only printing the condition when it was instantiation-dependent, that is, we called finish_static_assert from tsubst_expr. Moreover, this patch also improves the diagnostic when the condition consists of a logical AND. Say you have something like this: static_assert(fn1() && fn2() && fn3() && fn4() && fn5()); where fn4() evaluates to false and the other ones to true. Highlighting the whole thing is not that helpful because it won't say which clause evaluated to false. With the find_failing_clause tweak in this patch we emit: error: static assertion failed 6 | static_assert(fn1() && fn2() && fn3() && fn4() && fn5()); | ~~~^~ so you know right away what's going on. Unfortunately, when you combine both things, that is, have an instantiation-dependent expr and && in a static_assert, we can't yet quite point to the clause that failed. It is because when we tsubstitute something like is_same<X, Y>::value, we generate a VAR_DECL that doesn't have any location. It would be awesome if we could wrap it with a location wrapper, but I didn't see anything obvious. In passing, I've cleaned up some things: * use iloc_sentinel when appropriate, * it's nicer to call contextual_conv_bool instead of the rather verbose perform_implicit_conversion_flags, * no need to check for INTEGER_CST before calling integer_zerop. gcc/cp/ChangeLog: PR c++/97518 * cp-tree.h (finish_static_assert): Adjust declaration. * parser.c (cp_parser_static_assert): Pass false to finish_static_assert. * pt.c (tsubst_expr): Pass true to finish_static_assert. * semantics.c (find_failing_clause_r): New function. (find_failing_clause): New function. (finish_static_assert): Add a bool parameter. Use iloc_sentinel. Call contextual_conv_bool instead of perform_implicit_conversion_flags. Don't check for INTEGER_CST before calling integer_zerop. Call find_failing_clause and maybe use its location. Print the original condition or the failing clause if SHOW_EXPR_P. gcc/testsuite/ChangeLog: PR c++/97518 * g++.dg/diagnostic/pr87386.C: Adjust expected output. * g++.dg/diagnostic/static_assert1.C: New test. * g++.dg/diagnostic/static_assert2.C: New test. libcc1/ChangeLog: PR c++/97518 * libcp1plugin.cc (plugin_add_static_assert): Pass false to finish_static_assert.
2020-11-10openmp: Implement OpenMP 5.0 base-pointer attachement and clause orderingChung-Lin Tang1-20/+24
This patch implements some parts of the target variable mapping changes specified in OpenMP 5.0, including base-pointer attachment/detachment behavior for array section list-items in map clauses, and ordering of map clauses according to map kind. 2020-11-10 Chung-Lin Tang <cltang@codesourcery.com> gcc/c-family/ChangeLog: * c-common.h (c_omp_adjust_map_clauses): New declaration. * c-omp.c (struct map_clause): Helper type for c_omp_adjust_map_clauses. (c_omp_adjust_map_clauses): New function. gcc/c/ChangeLog: * c-parser.c (c_parser_omp_target_data): Add use of new c_omp_adjust_map_clauses function. Add GOMP_MAP_ATTACH_DETACH as handled map clause kind. (c_parser_omp_target_enter_data): Likewise. (c_parser_omp_target_exit_data): Likewise. (c_parser_omp_target): Likewise. * c-typeck.c (handle_omp_array_sections): Adjust COMPONENT_REF case to use GOMP_MAP_ATTACH_DETACH map kind for C_ORT_OMP region type. (c_finish_omp_clauses): Adjust bitmap checks to allow struct decl and same struct field access to co-exist on OpenMP construct. gcc/cp/ChangeLog: * parser.c (cp_parser_omp_target_data): Add use of new c_omp_adjust_map_clauses function. Add GOMP_MAP_ATTACH_DETACH as handled map clause kind. (cp_parser_omp_target_enter_data): Likewise. (cp_parser_omp_target_exit_data): Likewise. (cp_parser_omp_target): Likewise. * semantics.c (handle_omp_array_sections): Adjust COMPONENT_REF case to use GOMP_MAP_ATTACH_DETACH map kind for C_ORT_OMP region type. Fix interaction between reference case and attach/detach. (finish_omp_clauses): Adjust bitmap checks to allow struct decl and same struct field access to co-exist on OpenMP construct. gcc/ChangeLog: * gimplify.c (is_or_contains_p): New static helper function. (omp_target_reorder_clauses): New function. (gimplify_scan_omp_clauses): Add use of omp_target_reorder_clauses to reorder clause list according to OpenMP 5.0 rules. Add handling of GOMP_MAP_ATTACH_DETACH for OpenMP cases. * omp-low.c (is_omp_target): New static helper function. (scan_sharing_clauses): Add scan phase handling of GOMP_MAP_ATTACH/DETACH for OpenMP cases. (lower_omp_target): Add lowering handling of GOMP_MAP_ATTACH/DETACH for OpenMP cases. gcc/testsuite/ChangeLog: * c-c++-common/gomp/clauses-2.c: Remove dg-error cases now valid. * gfortran.dg/gomp/map-2.f90: Likewise. * c-c++-common/gomp/map-5.c: New testcase. libgomp/ChangeLog: * libgomp.h (enum gomp_map_vars_kind): Adjust enum values to be bit-flag usable. * oacc-mem.c (acc_map_data): Adjust gomp_map_vars argument flags to 'GOMP_MAP_VARS_OPENACC | GOMP_MAP_VARS_ENTER_DATA'. (goacc_enter_datum): Likewise for call to gomp_map_vars_async. (goacc_enter_data_internal): Likewise. * target.c (gomp_map_vars_internal): Change checks of GOMP_MAP_VARS_ENTER_DATA to use bit-and (&). Adjust use of gomp_attach_pointer for OpenMP cases. (gomp_exit_data): Add handling of GOMP_MAP_DETACH. (GOMP_target_enter_exit_data): Add handling of GOMP_MAP_ATTACH. * testsuite/libgomp.c-c++-common/ptr-attach-1.c: New testcase.
2020-11-04openmp: allocate clause vs. *reduction array sections [PR97670]Jakub Jelinek1-10/+42
This patch finds the base expression of reduction array sections and uses it in checks whether allocate clause lists only variables that have been privatized. Also fixes a pasto that caused an ICE. 2020-11-04 Jakub Jelinek <jakub@redhat.com> PR c++/97670 gcc/c-family/ * c-omp.c (c_omp_split_clauses): Look through array reductions to find underlying decl to clear in the allocate_head bitmap. gcc/c/ * c-typeck.c (c_finish_omp_clauses): Look through array reductions to find underlying decl to clear in the aligned_head bitmap. gcc/cp/ * semantics.c (finish_omp_clauses): Look through array reductions to find underlying decl to clear in the aligned_head bitmap. Use DECL_UID (t) instead of DECL_UID (OMP_CLAUSE_DECL (c)) when clearing in the bitmap. Only diagnose errors about allocate vars not being privatized on the same construct on allocate clause if it has a DECL_P OMP_CLAUSE_DECL. gcc/testsuite/ * c-c++-common/gomp/allocate-4.c: New test. * g++.dg/gomp/allocate-2.C: New test. * g++.dg/gomp/allocate-3.C: New test.
2020-10-30openmp: Handle non-static data members in allocate clause and other C++ ↵Jakub Jelinek1-13/+20
allocate fixes This allows specification of non-static data members in allocate clause like it can be specified in other privatization clauses and adds a new testcase that covers also handling of that clause in templates. 2020-10-30 Jakub Jelinek <jakub@redhat.com> * semantics.c (finish_omp_clauses) <case OMP_CLAUSE_ALLOCATE>: Handle non-static members in methods. * pt.c (tsubst_omp_clauses): Handle OMP_CLAUSE_ALLOCATE. * c-c++-common/gomp/allocate-1.c (qux): Add another test. * g++.dg/gomp/allocate-1.C: New test.
2020-10-28openmp: Parsing and some semantic analysis of OpenMP allocate clauseJakub Jelinek1-0/+93
This patch adds parsing of OpenMP allocate clause, but still ignores it during OpenMP lowering where we should for privatized variables with allocate clause use the corresponding allocators rather than allocating them on the stack. 2020-10-28 Jakub Jelinek <jakub@redhat.com> gcc/ * tree-core.h (enum omp_clause_code): Add OMP_CLAUSE_ALLOCATE. * tree.h (OMP_CLAUSE_ALLOCATE_ALLOCATOR, OMP_CLAUSE_ALLOCATE_COMBINED): Define. * tree.c (omp_clause_num_ops, omp_clause_code_name): Add allocate clause. (walk_tree_1): Handle OMP_CLAUSE_ALLOCATE. * tree-pretty-print.c (dump_omp_clause): Likewise. * gimplify.c (gimplify_scan_omp_clauses, gimplify_adjust_omp_clauses, gimplify_omp_for): Likewise. * tree-nested.c (convert_nonlocal_omp_clauses, convert_local_omp_clauses): Likewise. * omp-low.c (scan_sharing_clauses): Likewise. gcc/c-family/ * c-pragma.h (enum pragma_omp_clause): Add PRAGMA_OMP_CLAUSE_ALLOCATE. * c-omp.c: Include bitmap.h. (c_omp_split_clauses): Handle OMP_CLAUSE_ALLOCATE. gcc/c/ * c-parser.c (c_parser_omp_clause_name): Handle allocate. (c_parser_omp_clause_allocate): New function. (c_parser_omp_all_clauses): Handle PRAGMA_OMP_CLAUSE_ALLOCATE. (OMP_FOR_CLAUSE_MASK, OMP_SECTIONS_CLAUSE_MASK, OMP_PARALLEL_CLAUSE_MASK, OMP_SINGLE_CLAUSE_MASK, OMP_TASK_CLAUSE_MASK, OMP_TASKGROUP_CLAUSE_MASK, OMP_DISTRIBUTE_CLAUSE_MASK, OMP_TEAMS_CLAUSE_MASK, OMP_TARGET_CLAUSE_MASK, OMP_TASKLOOP_CLAUSE_MASK): Add PRAGMA_OMP_CLAUSE_ALLOCATE. * c-typeck.c (c_finish_omp_clauses): Handle OMP_CLAUSE_ALLOCATE. gcc/cp/ * parser.c (cp_parser_omp_clause_name): Handle allocate. (cp_parser_omp_clause_allocate): New function. (cp_parser_omp_all_clauses): Handle PRAGMA_OMP_CLAUSE_ALLOCATE. (OMP_FOR_CLAUSE_MASK, OMP_SECTIONS_CLAUSE_MASK, OMP_PARALLEL_CLAUSE_MASK, OMP_SINGLE_CLAUSE_MASK, OMP_TASK_CLAUSE_MASK, OMP_TASKGROUP_CLAUSE_MASK, OMP_DISTRIBUTE_CLAUSE_MASK, OMP_TEAMS_CLAUSE_MASK, OMP_TARGET_CLAUSE_MASK, OMP_TASKLOOP_CLAUSE_MASK): Add PRAGMA_OMP_CLAUSE_ALLOCATE. * semantics.c (finish_omp_clauses): Handle OMP_CLAUSE_ALLOCATE. * pt.c (tsubst_omp_clauses): Likewise. gcc/testsuite/ * c-c++-common/gomp/allocate-1.c: New test. * c-c++-common/gomp/allocate-2.c: New test. * c-c++-common/gomp/clauses-1.c (omp_allocator_handle_t): New typedef. (foo, bar, baz): Add allocate clauses where allowed.
2020-10-26c++: Implement __is_nothrow_constructible and __is_nothrow_assignableVille Voutilainen1-0/+8
gcc/c-family/ChangeLog: * c-common.c (__is_nothrow_assignable): New. (__is_nothrow_constructible): Likewise. * c-common.h (RID_IS_NOTHROW_ASSIGNABLE): New. (RID_IS_NOTHROW_CONSTRUCTIBLE): Likewise. gcc/cp/ChangeLog: * cp-tree.h (CPTK_IS_NOTHROW_ASSIGNABLE): New. (CPTK_IS_NOTHROW_CONSTRUCTIBLE): Likewise. (is_nothrow_xible): Likewise. * method.c (is_nothrow_xible): New. (is_trivially_xible): Tweak. * parser.c (cp_parser_primary_expression): Handle the new RID_*. (cp_parser_trait_expr): Likewise. * semantics.c (trait_expr_value): Handle the new RID_*. (finish_trait_expr): Likewise. libstdc++-v3/ChangeLog: * include/std/type_traits (__is_nt_constructible_impl): Remove. (__is_nothrow_constructible_impl): Adjust. (is_nothrow_default_constructible): Likewise. (__is_nt_assignable_impl): Remove. (__is_nothrow_assignable_impl): Adjust.
2020-10-01c++: pushdecl_top_level must set contextNathan Sidwell1-0/+1
I discovered pushdecl_top_level was not setting the decl's context, and we ended up with namespace-scope decls with NULL context. That broke modules. Then I discovered a couple of places where we set the context to a FUNCTION_DECL, which is also wrong. AFAICT the literals in question belong in global scope, as they're comdatable entities. But create_temporary would use current_scope for the context before we pushed it into namespace scope. This patch asserts the context is NULL and then sets it to the frobbed global_namespace. gcc/cp/ * name-lookup.c (pushdecl_top_level): Assert incoming context is null, add global_namespace context. (pushdecl_top_level_and_finish): Likewise. * pt.c (get_template_parm_object): Clear decl context before pushing. * semantics.c (finish_compound_literal): Likewise.
2020-09-24c++: Cleanup some decl pushing apisNathan Sidwell1-2/+2
In cleaning up local decl handling, here's an initial patch that takes advantage of C++'s default args for the is_friend parm of pushdecl, duplicate_decls and push_template_decl_real and the scope & tpl_header parms of xref_tag. Then many of the calls simply not mention these. I also rename push_template_decl_real to push_template_decl, deleting the original forwarding function. This'll make my later patches changing their types less intrusive. There are 2 functional changes: 1) push_template_decl requires is_friend to be correct, it doesn't go checking for a friend function (an assert is added). 2) debug_overload prints out Hidden and Using markers for the overload set. gcc/cp/ * cp-tree.h (duplicate_decls): Default is_friend to false. (xref_tag): Default tag_scope & tpl_header_p to ts_current & false. (push_template_decl_real): Default is_friend to false. Rename to ... (push_template_decl): ... here. Delete original decl. * name-lookup.h (pushdecl_namespace_level): Default is_friend to false. (pushtag): Default tag_scope to ts_current. * coroutines.cc (morph_fn_to_coro): Drop default args to xref_tag. * decl.c (start_decl): Drop default args to duplicate_decls. (start_enum): Drop default arg to pushtag & xref_tag. (start_preparsed_function): Pass DECL_FRIEND_P to push_template_decl. (grokmethod): Likewise. * friend.c (do_friend): Rename push_template_decl_real calls. * lambda.c (begin_lamnbda_type): Drop default args to xref_tag. (vla_capture_type): Likewise. * name-lookup.c (maybe_process_template_type_declaration): Rename push_template_decl_real call. (pushdecl_top_level_and_finish): Drop default arg to pushdecl_namespace_level. * pt.c (push_template_decl_real): Assert no surprising friend functions. Rename to ... (push_template_decl): ... here. Delete original function. (lookup_template_class_1): Drop default args from pushtag. (instantiate_class_template_1): Likewise. * ptree.c (debug_overload): Print hidden and using markers. * rtti.c (init_rtti_processing): Drop refault args from xref_tag. (build_dynamic_cast_1, tinfo_base_init): Likewise. * semantics.c (begin_class_definition): Drop default args to pushtag. gcc/objcp/ * objcp-decl.c (objcp_start_struct): Drop default args to xref_tag. (objcp_xref_tag): Likewise. libcc1/ * libcp1plugin.cc (supplement_binding): Drop default args to duplicate_decls. (safe_pushtag): Drop scope parm. Drop default args to pushtag. (safe_pushdecl_maybe_friend): Rename to ... (safe_pushdecl): ... here. Drop is_friend parm. Drop default args to pushdecl. (plugin_build_decl): Adjust safe_pushdecl & safe_pushtag calls. (plugin_build_constant): Adjust safe_pushdecl call.
2020-09-16c++: local-scope OMP UDR reductions have no template headNathan Sidwell1-8/+9
This corrects the earlier problems with removing the template header from local omp reductions. And it uncovered a latent bug. When we tsubst such a decl, we immediately tsubst its body. cp_check_omp_declare_reduction gets a success return value to gate that instantiation. udr-2.C got a further error, as the omp checking machinery doesn't appear to turn the reduction into an error mark when failing. I didn't dig into that further. udr-3.C appears to have been invalid and accidentally worked. gcc/cp/ * cp-tree.h (cp_check_omp_declare_reduction): Return bool. * semantics.c (cp_check_omp_declare_reduction): Return true on for success. * pt.c (push_template_decl_real): OMP reductions do not get a template header. (tsubst_function_decl): Remove special casing for local decl omp reductions. (tsubst_expr): Call instantiate_body for a local omp reduction. (instantiate_body): Add nested_p parm, and deal with such instantiations. (instantiate_decl): Reject FUNCTION_SCOPE entities, adjust instantiate_body call. gcc/testsuite/ * g++.dg/gomp/udr-2.C: Add additional expected error. libgomp/ * testsuite/libgomp.c++/udr-3.C: Add missing ctor.
2020-09-15OpenMP/Fortran: Fix (re)mapping of allocatable/pointer arrays [PR96668]Tobias Burnus1-2/+2
gcc/cp/ChangeLog: PR fortran/96668 * cp-gimplify.c (cxx_omp_finish_clause): Add bool openacc arg. * cp-tree.h (cxx_omp_finish_clause): Likewise * semantics.c (handle_omp_for_class_iterator): Update call. gcc/fortran/ChangeLog: PR fortran/96668 * trans.h (gfc_omp_finish_clause): Add bool openacc arg. * trans-openmp.c (gfc_omp_finish_clause): Ditto. Use GOMP_MAP_ALWAYS_POINTER with PSET for pointers. (gfc_trans_omp_clauses): Like the latter and also if the always modifier is used. gcc/ChangeLog: PR fortran/96668 * gimplify.c (gimplify_omp_for): Add 'bool openacc' argument; update omp_finish_clause calls. (gimplify_adjust_omp_clauses_1, gimplify_adjust_omp_clauses, gimplify_expr, gimplify_omp_loop): Update omp_finish_clause and/or gimplify_for calls. * langhooks-def.h (lhd_omp_finish_clause): Add bool openacc arg. * langhooks.c (lhd_omp_finish_clause): Likewise. * langhooks.h (lhd_omp_finish_clause): Likewise. * omp-low.c (scan_sharing_clauses): Keep GOMP_MAP_TO_PSET cause for 'declare target' vars. include/ChangeLog: PR fortran/96668 * gomp-constants.h (GOMP_MAP_ALWAYS_POINTER_P): Define. libgomp/ChangeLog: PR fortran/96668 * libgomp.h (struct target_var_desc): Add has_null_ptr_assoc member. * target.c (gomp_map_vars_existing): Add always_to_flag flag. (gomp_map_vars_existing): Update call to it. (gomp_map_fields_existing): Likewise (gomp_map_vars_internal): Update PSET handling such that if a nullptr is now allocated or if GOMP_MAP_POINTER is used PSET is updated and pointer remapped. (GOMP_target_enter_exit_data): Hanlde GOMP_MAP_ALWAYS_POINTER like GOMP_MAP_POINTER. * testsuite/libgomp.fortran/map-alloc-ptr-1.f90: New test. * testsuite/libgomp.fortran/map-alloc-ptr-2.f90: New test.
2020-09-10c++: DECL_LOCAL_FUNCTION_P -> DECL_LOCAL_DECL_PNathan Sidwell1-1/+1
Our handling of block-scope extern decls is insufficient for modern C++, in particular modules, (but also constexprs). We mark such local function decls, and this patch extends that to marking local var decls too, so mainly a macro rename. Also, we set this flag earlier, rather than learning about it when pushing the decl. This is a step towards handling these properly. gcc/cp/ * cp-tree.h (DECL_LOCAL_FUNCTION_P): Rename to ... (DECL_LOCAL_DECL_P): ... here. Accept both fns and vars. * decl.c (start_decl): Set DECL_LOCAL_DECL_P for local externs. (omp_declare_variant_finalize_one): Use DECL_LOCAL_DECL_P. (local_variable_p): Simplify. * name-lookup.c (set_decl_context_in_fn): Assert DECL_LOCAL_DECL_P is as expected. Simplify. (do_pushdecl): Don't set decl_context_in_fn for friends. (is_local_extern): Simplify. * call.c (equal_functions): Use DECL_LOCAL_DECL_P. * parser.c (cp_parser_postfix_expression): Likewise. (cp_parser_omp_declare_reduction): Likewise. * pt.c (check_default_tmpl_args): Likewise. (tsubst_expr): Assert nested reduction function is local. (type_dependent_expression_p): Use DECL_LOCAL_DECL_P. * semantics.c (finish_call_expr): Likewise. libcc1/ * libcp1plugin.cc (plugin_build_call_expr): Use DECL_LOCAL_DECL_P.
2020-09-01openmp: Check for PARM_DECL before using C_ARRAY_PARAMETER or ↵Jakub Jelinek1-1/+1
DECL_ARRAY_PARAMETER_P [PR96867] The C++ macro performs a PARM_DECL_CHECK, so will ICE if not tested on a PARM_DECL, C_ARRAY_PARAMETER doesn't, but probably should, otherwise it is testing e.g. C_DECL_VARIABLE_SIZE on VAR_DECLs. 2020-09-01 Jakub Jelinek <jakub@redhat.com> PR c++/96867 * c-typeck.c (handle_omp_array_sections_1): Test C_ARRAY_PARAMETER only on PARM_DECLs. * semantics.c (handle_omp_array_sections_1): Test DECL_ARRAY_PARAMETER_P only on PARM_DECLs. * c-c++-common/gomp/pr96867.c: New test.
2020-08-25OpenMP: Improve map-clause error message for array function parameter (PR96678)Tobias Burnus1-2/+7
gcc/c/ChangeLog: PR c/96678 * c-typeck.c (handle_omp_array_sections_1): Talk about array function parameter in the error message. gcc/cp/ChangeLog: PR c/96678 * semantics.c (handle_omp_array_sections_1): Talk about array function parameter in the error message. gcc/testsuite/ChangeLog: PR c/96678 * c-c++-common/gomp/map-4.c: New test. * c-c++-common/gomp/depend-1.c: Update dg-error. * c-c++-common/gomp/map-1.c: Likewise. * c-c++-common/gomp/reduction-1.c: Likewise. * g++.dg/gomp/depend-1.C: Likewise. * g++.dg/gomp/depend-2.C: Likewise.
2020-08-25c++: Fix up ptr.~PTR () handling [PR96721]Jakub Jelinek1-1/+1
The following testcase is miscompiled, because build_trivial_dtor_call handles the case when instance is a pointer by adding a clobber to what the pointer points to (which is desirable e.g. for delete) rather than the pointer itself. That is I think always desirable behavior for references, but for pointers for the pseudo dtor case it is not. 2020-08-25 Jakub Jelinek <jakub@redhat.com> PR c++/96721 * cp-tree.h (build_trivial_dtor_call): Add bool argument defaulted to false. * call.c (build_trivial_dtor_call): Add NO_PTR_DEREF argument. If instance is a pointer and NO_PTR_DEREF is true, clobber the pointer rather than what it points to. * semantics.c (finish_call_expr): Call build_trivial_dtor_call with true as NO_PTR_DEREF. * g++.dg/opt/flifetime-dse8.C: New test.
2020-08-14c++: Final bit of name-lookup api simplificationNathan Sidwell1-2/+2
We no longer need to give name_lookup_real not name_lookup_nonclass different names to the name_lookup functions. This renames the lookup functions thusly. gcc/cp/ * name-lookup.h (lookup_name_real, lookup_name_nonclass): Rename to ... (lookup_name): ... these new overloads. * name-lookup.c (identifier_type_value_1): Rename lookup_name_real call. (lookup_name_real_1): Rename to ... (lookup_name_1): ... here. (lookup_name_real): Rename to ... (lookup_name): ... here. Rename lookup_name_real_1 call. (lookup_name_nonclass): Delete. * call.c (build_operator_new_call): Rename lookup_name_real call. (add_operator_candidates): Likewise. (build_op_delete_call): Rename lookup_name_nonclass call. * parser.c (cp_parser_lookup_name): Likewise. * pt.c (tsubst_friend_class, lookup_init_capture_pack): Likewise. (tsubst_expr): Likewise. * semantics.c (capture_decltype): Likewise. libcc1/ * libcp1plugin.cc (plugin_build_dependent_expr): Rename lookup_name_real call.
2020-08-14c++: Yet more name-lookup api simplificationNathan Sidwell1-2/+2
This patch deals with LOOKUP_HIDDEN, which originally meant 'find hidden friends', but it's being pressed into service for not ignoring lambda-relevant internals. However these two functions are different. (a) hidden friends can occur in block scope (very uncommon) and (b) it had the semantics of stopping after the innermost enclosing namepspace. That's really suspect for the lambda case, but not relevant there because we never get to namespace scope (I think). Anyway, I've split the flag into two and adjusted the lambda callers to just search block scope. These two flags are added to the LOOK_want enum class, which allows dropping another parameter from the name lookup routines. The remaining LOOKUP_$FOO flags in cp-tree.h are, I think, now all related to features of overload resolution, conversion operators and reference binding. Nothing to do with /name/ lookup. gcc/cp/ * cp-tree.h (LOOKUP_HIDDEN): Delete. (LOOKUP_PREFER_RVALUE): Adjust initializer. * name-lookup.h (enum class LOOK_want): Add HIDDEN_FRIEND and HIDDEN_LAMBDA flags. (lookup_name_real): Drop flags parm. (lookup_qualified_name): Drop find_hidden parm. * name-lookup.c (class name_lookup): Drop hidden field, adjust ctors. (name_lookup::add_overload): Check want for hiddenness. (name_lookup::process_binding): Likewise. (name_lookup::search_unqualified): Likewise. (identifier_type_value_1): Adjust lookup_name_real call. (set_decl_namespace): Adjust name_lookup ctor. (qualify_lookup): Drop flags parm, use want for hiddenness. (lookup_qualified_name): Drop find_hidden parm. (lookup_name_real_1): Drop flags parm, adjust qualify_lookup calls. (lookup_name_real): Drop flags parm. (lookup_name_nonclass, lookup_name): Adjust lookup_name_real calls. (lookup_type_scope_1): Adjust qualify_lookup calls. * call.c (build_operator_new_call): Adjust lookup_name_real call. (add_operator_candidates): Likewise. * coroutines.cc (morph_fn_to_coro): Adjust lookup_qualified_name call. * parser.c (cp_parser_lookup_name): Adjust lookup_name_real calls. * pt.c (check_explicit_specialization): Adjust lookup_qualified_name call. (deduction_guides_for): Likewise. (tsubst_friend_class): Adjust lookup_name_real call. (lookup_init_capture_pack): Likewise. (tsubst_expr): Likewise, don't look in namespaces. * semantics.c (capture_decltype): Adjust lookup_name_real. Don't look in namespaces. libcc1/ * libcp1plugin.cc (plugin_build_dependent_exp): Adjust lookup_name_real call.
2020-08-14c++: More simplification of name_lookup apiNathan Sidwell1-2/+2
Continuing fixing name lookup's API we have two parameters saying what we'd like to find 'prefer_type', which is a tri-valued boolan with meaning 'don't care', 'type or namespace', 'type or death'. And we have a second parameter 'namespaces_only', which means 'namespace or death'. There are only 4 states, because the latter one has priority. Firstly 'prefer_type' isn't really the right name -- it's not a preference, it's a requirement. Name lookup maps those two parameters into 2 LOOKUP_ bits. We can simply have callers express that desire directly. So this adds another enum class, LOOK_want, which expresses all those options in 2 bits. Most of this patch is then the expected fallout from such a change. The parser was mapping its internal state into a prefer_type value, which was then mapped into the LOOKUP_ bits. So this saves a conversion there. Also the parser's conversion routine had an 'is_template' flag, which was only ever true in one place, where the parser also had to deal with other nuances of the flags to pass. So just drop that parm and deal with it at the call site too. I've left LOOKUP_HIDDEN alone for the moment. That'll be next. gcc/cp/ * cp-tree.h (LOOKUP_PREFER_TYPES, LOOKUP_PREFER_NAMESPACES) (LOOKUP_NAMESPACES_ONLY, LOOKUP_TYPES_ONLY) (LOOKUP_QUALIFIERS_ONL): Delete. (LOOKUP_HIDDEN): Adjust. * name-lookup.h (enum class LOOK_want): New. (operator|, operator&): Overloads for it. (lookup_name_real): Replace prefer_type & namespaces_only with LOOK_want parm. (lookup_qualified_name): Replace prefer_type with LOOK_want. (lookup_name_prefer_type): Replace with ... (lookup_name): ... this. New overload with LOOK_want parm. * name-lookup.c (struct name_lookup): Replace flags with want and hidden fields. Adjust constructors. (name_lookyp::add_overload): Correct hidden stripping test. Update for new LOOK_want type. (name_lookup::process_binding): Likewise. (name_lookup::search_unqualified): Use hidden flag. (identifier_type_value_1): Adjust lookup_name_real call. (set_decl_namespace): Adjust name_lookup ctor. (lookup_flags): Delete. (qualify_lookup): Add LOOK_want parm, adjust. (lookup_qualified_name): Replace prefer_type parm with LOOK_want. (lookup_name_real_1): Replace prefer_type and namespaces_only with LOOK_want parm. (lookup_name_real): Likewise. (lookup_name_nonclass, lookup_name): Adjust lookup_name_real call. (lookup_name_prefer_type): Rename to ... (lookup_name): ... here. New overload with LOOK_want parm. (lookup_type_scope_1): Adjust qualify_lookup calls. * call.c (build_operator_new_call) (add_operator_candidates): Adjust lookup_name_real calls. * coroutines.cc (find_coro_traits_template_decl) (find_coro_handle_template_decl, morph_fn_to_coro): Adjust lookup_qualified_name calls. * cp-objcp-common.c (identifier_global_tag): Likewise. * decl.c (get_tuple_size, get_tuple_decomp_init): Likewise. (lookup_and_check_tag): Use lookup_name overload. * parser.c (cp_parser_userdef_numeric_literal): Adjust lookup_qualified_name call. (prefer_arg_type): Drop template_mem_access parm, return LOOK_want value. (cp_parser_lookup_name): Adjust lookup_member, lookup_name_real calls. * pt.c (check_explicit_specialization): Adjust lookup_qualified_name call. (tsubst_copy_and_build, tsubst_qualified_name): Likewise (deduction_guides_for): Likewise. (tsubst_friend_class): Adjust lookup_name_real call. (lookup_init_capture, tsubst_expr): Likewise. * rtti.c (emit_support_tinfos): Adjust lookup_qualified_name call. * semantics.c (omp_reduction_lookup): Likewise. (capture_decltype): Adjust lookup_name_real call. libcc1/ * libcp1plugin.cc (plugin_build_dependent_expr): Adjust lookup_name_real & lookup_qualified_name calls.
2020-08-13[c++]: Unconfuse lookup_name_real API a bitNathan Sidwell1-2/+2
The API for lookup_name_real is really confusing. This addresses the part where we have NONCLASS to say DON'T search class scopes, and BLOCK_P to say DO search block scopes. I've added a single bitmask to explicitly say which scopes to search. I used an enum class so one can't accidentally misorder it. It's also reordered so we don't mix it up with the parameters that say what kind of thing we're looking for. gcc/cp/ * name-lookup.h (enum class LOOK_where): New. (operator|, operator&): Overloads for it. (lookup_name_real): Replace NONCLASS & BLOCK_P parms with WHERE. * name-lookup.c (identifier_type_value_w): Adjust lookup_name_real call. (lookup_name_real_1): Replace NONCLASS and BLOCK_P parameters with WHERE bitmask. Don't search namespaces if not asked to. (lookup_name_real): Adjust lookup_name_real_1 call. (lookup_name_nonclass, lookup_name) (lookup_name_prefer_type): Likewise. * call.c (build_operator_new_call) (add_operator_candidates): Adjust lookup_name_real calls. * parser.c (cp_parser_lookup_name): Likewise. * pt.c (tsubst_friend_class, lookup_init_capture_pack) (tsubst_expr): Likewise. * semantics.c (capture_decltype): Likewise. libcc1/ * libcp1plugin.cc (plugin_build_dependent_expr): Likewise.
2020-07-20c++: Pseudo-destructor ends object lifetime.Jason Merrill1-7/+14
P0593R6 is mostly about a new object model whereby malloc and the like are treated as implicitly starting the lifetime of whatever trivial types are necessary to give the program well-defined semantics; that seems only relevant to TBAA, and is not implemented here. The paper also specifies that a pseudo-destructor call (a destructor call for a non-class type) ends the lifetime of the object like a destructor call for an object of class type, even though it doesn't call a destructor; this patch implements that change. The paper was voted as a DR, so I'm applying this change to all standard levels. Like class end-of-life clobbers, it is controlled by -flifetime-dse. gcc/cp/ChangeLog: * pt.c (type_dependent_expression_p): A pseudo-dtor can be dependent. * semantics.c (finish_call_expr): Use build_trivial_dtor_call for pseudo-destructor. (finish_pseudo_destructor_expr): Leave type NULL for dependent arg. gcc/testsuite/ChangeLog: * g++.dg/opt/flifetime-dse7.C: New test.
2020-07-09openacc: Set bias to zero for explicit attach/detach clauses in C and C++Julian Brown1-0/+16
This is a fix for the pointer (or array) size inadvertently being used for the bias with attach and detach mapping kinds, for both C and C++. 2020-07-09 Julian Brown <julian@codesourcery.com> Thomas Schwinge <thomas@codesourcery.com> gcc/c/ PR middle-end/95270 * c-typeck.c (c_finish_omp_clauses): Set OMP_CLAUSE_SIZE (bias) to zero for standalone attach/detach clauses. gcc/cp/ PR middle-end/95270 * semantics.c (finish_omp_clauses): Likewise. include/ PR middle-end/95270 * gomp-constants.h (gomp_map_kind): Expand comment for attach/detach mapping kinds. gcc/testsuite/ PR middle-end/95270 * c-c++-common/goacc/mdc-1.c: Update expected dump output for zero bias. libgomp/ PR middle-end/95270 * testsuite/libgomp.oacc-c-c++-common/pr95270-1.c: New test. * testsuite/libgomp.oacc-c-c++-common/pr95270-2.c: New test.
2020-06-16openmp: Initial part of OpenMP 5.0 non-rectangular loop supportJakub Jelinek1-31/+43
OpenMP 5.0 adds support for non-rectangular loop collapses, e.g. triangular and more complex. This patch deals just with the diagnostics so that they aren't rejected immediately as before. As the spec generally requires as before that the iteration variable initializer and bound in the comparison as invariant vs. the outermost loop, and just add some exceptional forms that can violate that, we need to avoid folding the expressions until we can detect them and in order to avoid folding it later on, I chose to use a TREE_VEC in those expressions to hold the var_outer * expr1 + expr2 triplet, the patch adds pretty-printing of that, gimplification etc. and just sorry_at during omp expansion for now. The next step will be to implement the different cases of that one by one. 2020-06-16 Jakub Jelinek <jakub@redhat.com> gcc/ * tree.h (OMP_FOR_NON_RECTANGULAR): Define. * gimplify.c (gimplify_omp_for): Diagnose schedule, ordered or dist_schedule clause on non-rectangular loops. Handle gimplification of non-rectangular lb/b expressions. When changing iteration variable, adjust also non-rectangular lb/b expressions referencing that. * omp-general.h (struct omp_for_data_loop): Add m1, m2 and outer members. (struct omp_for_data): Add non_rect member. * omp-general.c (omp_extract_for_data): Handle non-rectangular loops. Fill in non_rect, m1, m2 and outer. * omp-low.c (lower_omp_for): Handle non-rectangular lb/b expressions. * omp-expand.c (expand_omp_for): Emit sorry_at for unsupported non-rectangular loop cases and assert for cases that can't be non-rectangular. * tree-pretty-print.c (dump_mem_ref): Formatting fix. (dump_omp_loop_non_rect_expr): New function. (dump_generic_node): Handle non-rectangular OpenMP loops. * tree-pretty-print.h (dump_omp_loop_non_rect_expr): Declare. * gimple-pretty-print.c (dump_gimple_omp_for): Handle non-rectangular OpenMP loops. gcc/c-family/ * c-common.h (c_omp_check_loop_iv_exprs): Add an int argument. * c-omp.c (struct c_omp_check_loop_iv_data): Add maybe_nonrect and idx members. (c_omp_is_loop_iterator): New function. (c_omp_check_loop_iv_r): Use it. Add support for silent scanning if outer loop iterator is present. Perform duplicate checking through hash_set in the function rather than expecting caller to do that. Pass NULL instead of d->ppset to walk_tree_1. (c_omp_check_nonrect_loop_iv): New function. (c_omp_check_loop_iv): Use it. Fill in new members, allow non-rectangular loop forms, diagnose multiple associated loops with the same iterator. Pass NULL instead of &pset to walk_tree_1. (c_omp_check_loop_iv_exprs): Likewise. gcc/c/ * c-parser.c (c_parser_expr_no_commas): Save, clear and restore c_in_omp_for. (c_parser_omp_for_loop): Set c_in_omp_for around some calls to avoid premature c_fully_fold. Defer explicit c_fully_fold calls to after c_finish_omp_for. * c-tree.h (c_in_omp_for): Declare. * c-typeck.c (c_in_omp_for): Define. (build_modify_expr): Avoid c_fully_fold if c_in_omp_for. (digest_init): Likewise. (build_binary_op): Likewise. gcc/cp/ * semantics.c (handle_omp_for_class_iterator): Adjust c_omp_check_loop_iv_exprs caller. (finish_omp_for): Likewise. Don't call fold_build_cleanup_point_expr before calling c_finish_omp_for and c_omp_check_loop_iv, move it after those calls. * pt.c (tsubst_omp_for_iterator): Handle non-rectangular loops. gcc/testsuite/ * c-c++-common/gomp/loop-6.c: New test. * gcc.dg/gomp/loop-1.c: Don't expect diagnostics on valid non-rectangular loops. * gcc.dg/gomp/loop-2.c: New test. * g++.dg/gomp/loop-1.C: Don't expect diagnostics on valid non-rectangular loops. * g++.dg/gomp/loop-2.C: Likewise. * g++.dg/gomp/loop-5.C: New test. * g++.dg/gomp/loop-6.C: New test.
2020-06-16c++: TI_DEFERRED_ACCESS_CHECKS and dependent declsPatrick Palka1-0/+7
This adds an assert to enforce_access to verify that we don't defer access checks of dependent decls -- we should instead be rechecking the access of such a decl after tsubst'ing into the user of the decl. gcc/cp/ChangeLog: * pt.c (perform_instantiation_time_access_checks): No need to tsubst into decl. * semantics.c (enforce_access): Verify that decl is not dependent.
2020-06-16c++: Clean up previous change [PR41437]Patrick Palka1-6/+6
The previous patch mostly avoided making any changes that had no functional impact, such as adjusting now-outdated comments and performing renamings. Such changes have been consolidated to this followup patch for easier review. The main change here is that we now reuse struct deferred_access_check as the element type of the vector TI_TYPEDEFS_NEEDING_ACCESS_CHECKING (now renamed to TI_DEFERRED_ACCESS_CHECKS, since it may contain any kind of access check). gcc/cp/ChangeLog: PR c++/41437 PR c++/47346 * cp-tree.h (qualified_typedef_usage_s): Delete. (qualified_typedef_usage_t): Delete. (deferred_access_check): Move up in file. (tree_template_info::typedefs_needing_access_checking): Delete. (tree_template_info::deferred_access_checks): New field. (TI_TYPEDEFS_NEEDING_ACCESS_CHECKING): Rename to ... (TI_DEFERRED_ACCESS_CHECKS): ... this, and adjust accordingly. * pt.c (perform_typedefs_access_check): Rename to ... (perform_instantiation_time_access_checks): ... this, and adjust accordingly. Remove unnecessary tree tests. (instantiate_class_template_1): Adjust accordingly. (instantiate_decl): Likewise. * semantics.c (enforce_access): Likewise.
2020-06-16c++: Improve access checking inside templates [PR41437]Patrick Palka1-51/+72
This patch generalizes our existing functionality for deferring access checking of typedefs when parsing a function or class template to now defer all kinds of access checks until template instantiation time, including member function and member object accesses. Since all access checks eventually go through enforce_access, the main component of this patch is new handling inside enforce_access to defer the current access check if we're inside a template. The bulk of the rest of the patch consists of removing now-unneeded code pertaining to suppressing access checks inside templates or pertaining to typedef-specific access handling. Renamings and other changes with no functional impact have been split off into the followup patch. gcc/cp/ChangeLog: PR c++/41437 PR c++/47346 * call.c (enforce_access): Move to semantics.c. * cp-tree.h (enforce_access): Delete. (get_types_needing_access_check): Delete. (add_typedef_to_current_template_for_access_check): Delete. * decl.c (make_typename_type): Adjust accordingly. Use check_accessibility_of_qualified_id instead of directly using perform_or_defer_access_check. * parser.c (cp_parser_template_declaration_after_parameters): Don't push a dk_no_check access state when parsing a template. * pt.c (get_types_needing_access_check): Delete. (append_type_to_template_for_access_check_1): Delete. (perform_typedefs_access_check): Adjust. If type_decl is a FIELD_DECL, also check its DECL_CONTEXT for dependence. Use tsubst_copy instead of tsubst to substitute into type_decl so that we substitute into the DECL_CONTEXT of a FIELD_DECL. (append_type_to_template_for_access_check): Delete. * search.c (accessible_p): Remove the processing_template_decl early exit. * semantics.c (enforce_access): Moved from call.c. If we're parsing a template and the access check failed, add the check to TI_TYPEDEFS_NEEDING_ACCESS_CHECKING. (perform_or_defer_access_check): Adjust comment. (add_typedef_to_current_template_for_access_check): Delete. (check_accessibility_of_qualified_id): Adjust accordingly. Exit early if the scope is dependent. gcc/testsuite/ChangeLog: PR c++/41437 PR c++/47346 * g++.dg/cpp2a/concepts-using2.C: Adjust. * g++.dg/lto/20081219_1.C: Adjust. * g++.dg/lto/20091002-1_0.C: Adjust. * g++.dg/lto/pr65475c_0.C: Adjust. * g++.dg/opt/dump1.C: Adjust. * g++.dg/other/pr53574.C: Adjust. * g++.dg/template/access30.C: New test. * g++.dg/template/access31.C: New test. * g++.dg/wrappers/wrapper-around-type-pack-expansion.C: Adjust. libstdc++-v3/ChangeLog: PR libstdc++/94003 * testsuite/20_util/is_constructible/94003.cc: New test.
2020-05-15c++: decltype of invalid non-dependent expr [PR57943]Patrick Palka1-0/+8
We sometimes fail to reject an invalid non-dependent operand to decltype when inside a template, because finish_decltype_type resolves the decltype to the TREE_TYPE of the operand before we ever instantiate and fully process the operand. Fix this by adding a call to instantiate_non_dependent_expr_sfinae in finish_decltype_type. gcc/cp/ChangeLog: PR c++/57943 * semantics.c (finish_decltype_type): Call instantiate_non_dependent_expr_sfinae on the expression. gcc/testsuite/ChangeLog: PR c++/57943 * g++.dg/cpp0x/decltype76.C: New test.
2020-05-13c++: Formatting fixups & some simplifications.Nathan Sidwell1-3/+2
A bunch of minor reformatting, simplifications or change to checking_asserts. * pt.c (spec_hash_table): New typedef. (decl_specializations, type_specializations): Use it. (retrieve_specialization): Likewise. (register_specialization): Remove unnecessary casts. (push_template_decl_real): Reformat. (instantiate_class_template_1): Use more RAII. (make_argument_pack): Simplify. (instantiate_template_1): Use gcc_checking_assert for expensive asserts. (instantiate_decl): Likewise. (resolve_typename_type): Reformat comment. * semantics.c (struct deferred_access): Remove unnecessary GTY on member. (begin_class_definition): Fix formatting.
2020-05-01c++: Missing SFINAE with inaccessible static data member [PR90880]Patrick Palka1-7/+11
This is a missing SFINAE issue when verifying the accessibility of a static data member. The cause is that check_accessibility_of_qualified_id unconditionally passes tf_warning_or_error to perform_or_defer_access_check, even when called from tsubst_qualified_id(..., complain=tf_none). This patch fixes this by plumbing 'complain' from tsubst_qualified_id through check_accessibility_of_qualified_id to reach perform_or_defer_access_check, and by giving check_accessibility_of_qualified_id the appropriate return value. gcc/cp/ChangeLog: PR c++/90880 * cp-tree.h (check_accessibility_of_qualified_id): Add tsubst_flags_t parameter and change return type to bool. * parser.c (cp_parser_lookup_name): Pass tf_warning_to_error to check_accessibility_of_qualified_id. * pt.c (tsubst_qualified_id): Return error_mark_node if check_accessibility_of_qualified_id returns false. * semantics.c (check_accessibility_of_qualified_id): Add complain parameter. Pass complain instead of tf_warning_or_error to perform_or_defer_access_check. Return true unless perform_or_defer_access_check returns false. gcc/testsuite/ChangeLog: PR c++/90880 * g++.dg/template/sfinae29.C: New test.
2020-04-25c++: Avoid -Wreturn-type warning if a template fn calls noreturn template fn ↵Jakub Jelinek1-1/+1
[PR94742] finish_call_expr already has code to set current_function_returns_abnormally if a template calls a noreturn function, but on the following testcase it doesn't call a FUNCTION_DECL, but TEMPLATE_DECL instead, in which case we didn't check noreturn at all and just assumed it could return. 2020-04-25 Jakub Jelinek <jakub@redhat.com> PR c++/94742 * semantics.c (finish_call_expr): When looking if all overloads are noreturn, use STRIP_TEMPLATE to look through TEMPLATE_DECLs. * g++.dg/warn/Wreturn-type-12.C: New test.
2020-03-30c++: Fix handling of internal fn calls in statement expressions [PR94385]Jakub Jelinek1-1/+2
The following testcase ICEs, because the FE when processing the statement expression changes the .VEC_CONVERT internal fn CALL_EXPR into .PHI call. That is because the internal fn call is recorded in the base.u.ifn field, which overlaps base.u.bits.lang_flag_1 which is used for STMT_IS_FULL_EXPR_P, so this essentially does ifn |= 2 on little-endian. STMT_IS_FULL_EXPR_P bit is used in: cp-gimplify.c- if (STATEMENT_CODE_P (code)) cp-gimplify.c- { cp-gimplify.c- saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p (); cp-gimplify.c- current_stmt_tree ()->stmts_are_full_exprs_p cp-gimplify.c: = STMT_IS_FULL_EXPR_P (*expr_p); cp-gimplify.c- } and pt.c- if (STATEMENT_CODE_P (TREE_CODE (t))) pt.c: current_stmt_tree ()->stmts_are_full_exprs_p = STMT_IS_FULL_EXPR_P (t); so besides being wrong on some other codes, it actually isn't beneficial at all to set it on anything else, so the following patch restricts it to trees with STATEMENT_CODE_P TREE_CODE. 2020-03-30 Jakub Jelinek <jakub@redhat.com> PR c++/94385 * semantics.c (add_stmt): Only set STMT_IS_FULL_EXPR_P on trees with STATEMENT_CODE_P code. * c-c++-common/pr94385.c: New test.
2020-03-28c++: requires-expression outside of a template is misevaluated [PR94252]Patrick Palka1-2/+4
This PR shows that a REQUIRES_EXPR outside of a template can sometimes be misevaluated. This happens because the evaluation routine tsubst_requires_expr (and diagnose_requires_expr) assumes the REQUIRES_EXPR's subtrees are templated trees and that therefore it's safe to call tsubst_expr on them. But this assumption isn't valid when we've parsed a REQUIRES_EXPR outside of a template context. In order to make this assumption valid here, this patch sets processing_template_decl to non-zero before parsing the body of a REQUIRES_EXPR so that its subtrees are indeed always templated trees. gcc/cp/ChangeLog: PR c++/94252 * constraint.cc (tsubst_compound_requirement): Always suppress errors from type_deducible_p and expression_convertible_p, as they're not substitution errors. (diagnose_atomic_constraint) <case INTEGER_CST>: Remove this case so that we diagnose INTEGER_CST expressions of non-bool type via the default case. * cp-gimplify.c (cp_genericize_r) <case REQUIRES_EXPR>: New case. * parser.c (cp_parser_requires_expression): Always parse the requirement body as if we're processing a template, by temporarily incrementing processing_template_decl. Afterwards, if we're not actually in a template context, perform semantic processing to diagnose any invalid types and expressions. * pt.c (tsubst_copy_and_build) <case REQUIRES_EXPR>: Remove dead code. * semantics.c (finish_static_assert): Explain an assertion failure when the condition is a REQUIRES_EXPR like we do when it is a concept check. gcc/testsuite/ChangeLog: PR c++/94252 * g++.dg/concepts/diagnostic7.C: New test. * g++.dg/concepts/pr94252.C: New test. * g++.dg/cpp2a/concepts-requires18.C: Adjust to expect an additional diagnostic.
2020-02-05c++: Mark __builtin_convertvector operand as read [PR93557]Jakub Jelinek1-1/+2
In C++ we weren't calling mark_exp_read on the __builtin_convertvector first argument. I guess it could misbehave even with lambda implicit captures. Fixed by calling decay_conversion on the argument, we use the argument as rvalue so we want the standard lvalue to rvalue conversions, but as the argument must be a vector type, e.g. integral promotions aren't really needed. 2020-02-05 Jakub Jelinek <jakub@redhat.com> PR c++/93557 * semantics.c (cp_build_vec_convert): Call decay_conversion on arg prior to passing it to c_build_vec_convert. * c-c++-common/Wunused-var-17.c: New test.
2020-01-31c++: Fix sizeof VLA lambda capture.Jason Merrill1-2/+9
sizeof a VLA type is not a constant in C or the GNU C++ extension, so we need to capture the VLA even in unevaluated context. For PR60855 we stopped looking through a previous capture, but we also need to capture the first time the variable is mentioned. PR c++/86216 * semantics.c (process_outer_var_ref): Capture VLAs even in unevaluated context.
2020-01-26c++: avoid ICE with __builtin_memset (PR90997).Jason Merrill1-1/+0
warn_for_memset calls fold_for_warn, which calls fold_non_dependent_expr, so also calling instantiate_non_dependent_expr here is undesirable. PR c++/90997 * semantics.c (finish_call_expr): Don't call instantiate_non_dependent_expr before warn_for_memset.
2020-01-22PR c++/93324 - ICE with -Wall on constexpr if.Marek Polacek1-0/+3
This is a crash with constexpr if, when trying to see if the call in the if-statement is std::is_constant_evaluated. cp_get_callee_fndecl_nofold can return NULL_TREE and fndecl_built_in_p doesn't expect to get a null tree, so check FNDECL first.
2020-01-01Update copyright years.Jakub Jelinek1-1/+1
From-SVN: r279813