aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
AgeCommit message (Collapse)AuthorFilesLines
2020-03-08c++: Fix pretty printing of TYPENAME_TYPEsPatrick Palka2-1/+7
I noticed that in some concepts diagnostic messages, we were printing typename types incorrectly, e.g. printing remove_reference_t<T> as typename remove_reference<T>::remove_reference_t instead of typename remove_reference<T>::type. Fix this by printing the TYPENAME_TYPE_FULLNAME instead of the TYPE_NAME in cxx_pretty_printer::simple_type_specifier, which is consistent with how dump_typename in error.c does it. gcc/cp/ChangeLog: * cxx-pretty-print.c (cxx_pretty_printer::simple_type_specifier) [TYPENAME_TYPE]: Print the TYPENAME_TYPE_FULLNAME instead of the TYPE_NAME. gcc/testsuite/ChangeLog: * g++.dg/concepts/diagnostic4.C: New test.
2020-03-06Fix mangling ICE [PR94027]Nathan Sidwell2-1/+9
PR c++/94027 * mangle.c (find_substitution): Don't call same_type_p on template args that cannot match. Now same_type_p rejects argument packs, we need to be more careful calling it with template argument vector contents. The mangler needs to do some comparisons to find the special substitutions. While that code looks a little ugly, this seems the smallest fix.
2020-03-04PR c++/90938 - Initializing array with {1} works but not {0}Martin Sebor2-1/+15
gcc/cp/ChangeLog: PR c++/90938 * tree.c (type_initializer_zero_p): Fail for structs initialized with non-structs. gcc/testsuite/ChangeLog: PR c++/90938 * g++.dg/init/array55.C: New test. * g++.dg/init/array56.C: New test. * g++.dg/cpp2a/nontype-class33.C: New test.
2020-03-04c++: Fix [[no_unique_address]] and default mem-init [PR90432]Jason Merrill3-0/+16
output_constructor doesn't like two consecutive entries with fields at the same position; let's avoid adding the one for the empty field. gcc/cp/ChangeLog 2020-03-04 Jason Merrill <jason@redhat.com> PR c++/90432 * init.c (perform_member_init): Don't do aggregate initialization of empty field. * constexpr.c (cx_check_missing_mem_inits): Don't enforce initialization of empty field.
2020-03-04Wrap array in ctor with braces.Martin Liska2-3/+8
* method.c: Wrap array in ctor with braces in order to silent clang warnings.
2020-03-03c++: Fix mismatch in template argument deduction [PR90505]Marek Polacek2-6/+15
My GCC 9 patch for C++20 P0846R0 (ADL and function templates) tweaked cp_parser_template_name to only return an identifier if name lookup didn't find anything. In the deduce4.C case it means that we now return an OVERLOAD. That means that cp_parser_template_id will call lookup_template_function whereby producing a TEMPLATE_ID_EXPR with unknown_type_node. Previously, we created a TEMPLATE_ID_EXPR with no type, making it type-dependent. What we have now is no longer type-dependent. And so, when we call finish_call_expr after we've parsed "foo<int>(10)", even though we're in a template, we still do the normal processing, thus perform overload resolution. When adding the template candidate foo we need to deduce the template arguments, and that is where things go downhill. When fn_type_unification sees that we have explicit template arguments, but they aren't complete, it will use them to substitute the function type. So we substitute e.g. "void <T33d> (U)". But the explicit template argument was for a different parameter so we don't actually substitute anything. But the problem here was that we reduced the template level of 'U' anyway. So then when we're actually deducing the template arguments via type_unification_real, we fail in unify: 22932 if (TEMPLATE_TYPE_LEVEL (parm) 22933 != template_decl_level (tparm)) 22934 /* The PARM is not one we're trying to unify. Just check 22935 to see if it matches ARG. */ because 'parm' has been reduced but 'tparm' has not yet. Therefore we shouldn't reduce the template level of template parameters when tf_partial aka template argument deduction substitution. But we can only return after performing the cp_build_qualified_type etc. business otherwise things break horribly. 2020-03-03 Jason Merrill <jason@redhat.com> Marek Polacek <polacek@redhat.com> PR c++/90505 - mismatch in template argument deduction. * pt.c (tsubst): Don't reduce the template level of template parameters when tf_partial. * g++.dg/template/deduce4.C: New test. * g++.dg/template/deduce5.C: New test. * g++.dg/template/deduce6.C: New test. * g++.dg/template/deduce7.C: New test.
2020-03-04coroutines: Handle component_ref in captures_temporaryJunMa2-5/+20
gcc/cp * coroutines.cc (captures_temporary): Strip component_ref to its base object. gcc/testsuite * g++.dg/coroutines/torture/co-await-15-capture-comp-ref.C: New test.
2020-03-03c++: Fix non-constant TARGET_EXPR constexpr handing [PR93998]Jakub Jelinek2-4/+14
We ICE on the following testcase since I've added the SAVE_EXPR-like constexpr handling where the TARGET_EXPR initializer (and cleanup) is evaluated only once (because it might have side-effects like new or delete expressions in it). The problem is if the TARGET_EXPR (but I guess in theory SAVE_EXPR too) initializer is *non_constant_p. We still remember the result, but already not that it is *non_constant_p. Normally that wouldn't be a big problem, if something is *non_constant_p, we only or into it and so the whole expression will be non-constant too. Except in the builtins handling, we try to evaluate the arguments with non_constant_p pointing into a dummy1 bool which we ignore. This is because some builtins might fold into a constant even if they don't have a constexpr argument. Unfortunately if we evaluate the TARGET_EXPR first in the argument of such a builtin and then once again, we don't set *non_constant_p. So, either we don't remember the TARGET_EXPR/SAVE_EXPR result if it wasn't constant, like the following patch does, or we could remember it, but in some way that would make it clear that it is non-constant (e.g. by pushing into the global->values SAVE_EXPR, SAVE_EXPR entry and perhaps for TARGET_EXPR don't remember it on TARGET_EXPR_SLOT, but the TARGET_EXPR itself and similarly push TARGET_EXPR, TARGET_EXPR and if we see those after the lookup, diagnose + set *non_constant_p. Or we could perhaps during the builtin argument evaluation push expressions into a different save_expr vec and undo them afterwards. 2020-03-03 Jakub Jelinek <jakub@redhat.com> PR c++/93998 * constexpr.c (cxx_eval_constant_expression) <case TARGET_EXPR, case SAVE_EXPR>: Don't record anything if *non_constant_p is true. * g++.dg/ext/pr93998.C: New test.
2020-03-03Build coroutine expression with unknown_type in processing_template_decl phase.JunMa3-3/+16
gcc/cp * coroutines.cc (finish_co_await_expr): Build co_await_expr with unknown_type_node. (finish_co_yield_expr): Ditto. *pt.c (type_dependent_expression_p): Set co_await/yield_expr with unknown type as dependent. gcc/testsuite * g++.dg/coroutines/torture/co-await-14-template-traits.C: New test.
2020-03-02coroutines: Update lambda capture handling to n4849.Iain Sandoe2-108/+81
In the absence of specific comment on the handling of closures I'd implemented something more than was intended (extending the lifetime of lambda capture-by-copy vars to the duration of the coro). After discussion at WG21 in February and by email, the correct handling is to treat the closure "this" pointer the same way as for a regular one, and thus it is the user's responsibility to ensure that the lambda capture object has suitable lifetime for the coroutine. It is noted that users frequently get this wrong, so it would be a good thing to revisit for C++23. This patch removes the additional copying behaviour for lambda capture-by- copy vars. gcc/cp/ChangeLog: 2020-03-02 Iain Sandoe <iain@sandoe.co.uk> * coroutines.cc (struct local_var_info): Adjust to remove the reference to the captured var, and just to note that this is a lambda capture proxy. (transform_local_var_uses): Handle lambda captures specially. (struct param_frame_data): Add a visited set. (register_param_uses): Also check for param uses in lambda capture proxies. (struct local_vars_frame_data): Remove captures list. (register_local_var_uses): Handle lambda capture proxies by noting and bypassing them. (morph_fn_to_coro): Update to remove lifetime extension of lambda capture-by-copy vars. gcc/testsuite/ChangeLog: 2020-03-02 Iain Sandoe <iain@sandoe.co.uk> Jun Ma <JunMa@linux.alibaba.com> * g++.dg/coroutines/torture/class-05-lambda-capture-copy-local.C: * g++.dg/coroutines/torture/lambda-09-init-captures.C: New test. * g++.dg/coroutines/torture/lambda-10-mutable.C: New test.
2020-03-02coroutines: Don't make duplicate frame copies of awaitables.Iain Sandoe2-26/+75
In general, we need to manage the lifetime of compiler- generated awaitable instances in the coroutine frame, since these must persist across suspension points. However, it is quite possible that the user might provide the awaitable instances, either as function params or as a local variable. We will already generate a frame entry for these as required. At present, under this circumstance, we are duplicating these, awaitable, initialising a second frame copy for them (which we then subsequently destroy manually after the suspension point). That's not efficient - so an undesirable thinko in the first place. However, there is also an actual bug; if the compiler elects to elide the copy (which is perfectly legal), it does not have visibility of the manual management of the post-suspend destruction - this subsequently leads to double-free errors. The solution is not to make the second copy (as noted, params and local vars already have frame copies with managed lifetimes). gcc/cp/ChangeLog: 2020-03-02 Iain Sandoe <iain@sandoe.co.uk> * coroutines.cc (build_co_await): Do not build frame proxy vars when the co_await expression is a function parameter or local var. (co_await_expander): Do not initialise a frame var with itself. (transform_await_expr): Only substitute the awaitable frame var if it's needed. (register_awaits): Do not make frame copies for param or local vars that are awaitables. gcc/testsuite/ChangeLog: 2020-03-02 Iain Sandoe <iain@sandoe.co.uk> * g++.dg/coroutines/torture/func-params-09-awaitable-parms.C: New test. * g++.dg/coroutines/torture/local-var-5-awaitable.C: New test.
2020-02-29c++: implement C++20 Disambiguating Nested-Requirements (P2092R0)Jason Merrill2-2/+6
The rule change in the title matches GCC's current behavior, so no change was needed. But the paper also makes 'typename' optional in a requirement-parameter-list, so this implements that. gcc/cp/ChangeLog 2020-02-28 Jason Merrill <jason@redhat.com> Implement P2092R0, Disambiguating Nested-Requirements * parser.c (cp_parser_requirement_parameter_list): Pass CP_PARSER_FLAGS_TYPENAME_OPTIONAL.
2020-02-28c++: Fix constrained conversion op.Jason Merrill2-0/+9
We don't want to promote a conversion from viable == 0 to viable == -1. Found in ranges-v3. gcc/cp/ChangeLog 2020-02-28 Jason Merrill <jason@redhat.com> * call.c (build_user_type_conversion_1): Don't look at the second conversion of a non-viable candidate.
2020-02-28c++: Further tweak for P1937R2 - const{expr,eval} inconsistenciesJakub Jelinek2-0/+7
Seems I've missed one thing, as the first hunk in https://github.com/cplusplus/draft/commit/c8e68ed202b4a9260616bcee8a9768b5dca4bbca changes the wording so that only potentially-evaluated id-expressions that denote immediate functions must appear only in the specified contexts. That IMO means that in unevaluated contexts there aren't such restrictions anymore, so I think in unevaluated contexts one should be able to take the address of an immediate function. 2020-02-28 Jakub Jelinek <jakub@redhat.com> P1937R2 - Fixing inconsistencies between const{expr,eval} functions * typeck.c (cp_build_addr_expr_1): Allow taking address of immediate functions in unevaluated contexts. * g++.dg/cpp2a/consteval3.C: Change dg-error about taking address of immediate function in unevaluated contexts into dg-bogus. * g++.dg/cpp2a/consteval16.C: New test.
2020-02-27Compare ARGUMENT_PACKS [pr93933]Nathan Sidwell4-20/+28
This implements Jason's suggested approach: 'I'd think that the bug is that we're treating them as types in the first place; they aren't types, so they shouldn't reach comptypes. I'd lean toward adding an assert to that effect and fixing the caller to use e.g. template_args_equal.' PR c++/93933 * pt.c (template_args_equal): Pass ARGUMENT_PACKS through to cp_tree_equal. * tree.c (cp_tree_equal): Compare ARGUMENT_PACKS here, * typeck.c (comptypes): Assert we don't get any argument packs.
2020-02-27Fix broken type comparison assertNathan Sidwell3-2/+10
In implementing Jason's suggested direction for 93933, the compiler exploded in a surprising way. Turns out an assert had been passing NULLS to comptypes, and therefore not checking what it intended. Further comptypes, could silently accept such nulls under most circumstances. * class.c (adjust_clone_args): Correct arg-checking assert. * typeck.c (comptypes): Assert not nulls.
2020-02-26c++: Fix ICE with invalid array bounds [PR93789]Marek Polacek2-3/+14
r7-2111 introduced maybe_constant_value in cp_fully_fold. maybe_constant_value uses cxx_eval_outermost_constant_expr, which can clear TREE_CONSTANT: 6510 else if (non_constant_p && TREE_CONSTANT (r)) [...] 6529 TREE_CONSTANT (r) = false; In this test the array size is '(long int) "h"'. This used to be TREE_CONSTANT but given the change above, the flag will be cleared when we cp_fully_fold the array size in compute_array_index_type_loc. That means we don't emit an error in the 10391 else if (TREE_CONSTANT (size) block in the same function, and we go on. Then we compute ITYPE using cp_build_binary_op and use maybe_constant_value on it and suddenly we have something that's TREE_CONSTANT again. And then we crash in reshape_init_array_1 in tree_to_uhwi, because what we have doesn't fit in an unsigned HWI. icc accepts this code, but since we used to reject it, I see no desire to make this work, so don't use the folded result when we've lost the TREE_CONSTANT flag while evaluating the size. 2020-02-26 Marek Polacek <polacek@redhat.com> PR c++/93789 - ICE with invalid array bounds. * decl.c (compute_array_index_type_loc): Don't use the folded size when folding cleared TREE_CONSTANT. * g++.dg/ext/vla22.C: New test.
2020-02-26coroutines: Amend parameter handling to match n4849.Iain Sandoe4-129/+211
In n4849 and preceding versions, [class.copy.elision] (1.3) appears to confer additional permissions on coroutines to elide parameter copies. After considerable discussion on this topic by email and during the February 2020 WG21 meeting, it has been determined that there are no additional permissions applicable to coroutine parameter copy elision. The content of that clause in the standard is expected to be amended eventually to clarify this. Other than this, the handling of parameter lifetimes is expected to be as per n4849: * A copy is made before the promise is constructed * If the promise CTOR uses the parms, then it should use the copy where appropriate. * The param copy lifetimes end after the promise is destroyed (during the coroutine frame destruction). * Otherwise, C++20 copy elision rules apply. (as an aside) In practice, we expect that copy elision can only occur when the coroutine body is fully inlined, possibly in conjunction with heap allocation elision. The patch: * Reorders the copying process to precede the promise CTOR and ensures the correct use. * Copies all params into the frame regardless of whether the coro body uses them (this is a bit unfortunate, and we should figure out an amendment for C++23). gcc/cp/ChangeLog: 2020-02-26 Iain Sandoe <iain@sandoe.co.uk> * class.c (classtype_has_non_deleted_copy_ctor): New. * coroutines.cc (struct param_info): Keep track of params that are references, and cache the original type and whether the DTOR is trivial. (build_actor_fn): Handle param copies always, and adjust the handling for references. (register_param_uses): Only handle uses here. (classtype_has_non_deleted_copy_ctor): New. (morph_fn_to_coro): Adjust param copy handling to match n4849 by reordering ahead of the promise CTOR and always making a frame copy, even if the param is unused in the coroutine body. * cp-tree.h (classtype_has_non_deleted_copy_ctor): New. gcc/testsuite/ChangeLog: 2020-02-26 Iain Sandoe <iain@sandoe.co.uk> * g++.dg/coroutines/coro1-refs-and-ctors.h: New. * g++.dg/coroutines/torture/func-params-07.C: New test. * g++.dg/coroutines/torture/func-params-08.C: New test.
2020-02-26c++: Some improvements to concept diagnosticsPatrick Palka3-14/+52
This patch improves our concept diagnostics in two ways. First, it sets a more precise location for the constraint expressions built in finish_constraint_binary_op. As a result, when a disjunction is unsatisfied we now print e.g. .../include/bits/range_access.h:467:2: note: neither operand of the disjunction is satisfied 466 | requires is_bounded_array_v<remove_reference_t<_Tp>> || __member_end<_Tp> | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 467 | || __adl_end<_Tp> | ^~~~~~~~~~~~~~~~~ instead of .../include/bits/range_access.h:467:2: note: neither operand of the disjunction is satisfied 467 | || __adl_end<_Tp> | ^~ Second, this patch changes diagnose_atomic_constraint to print unsatisfied atomic constraint expressions with their template arguments. So e.g. we now print cpp2a/concepts-pr67719.C:9:8: note: the expression ‘(... &&(C<Tx>)()) [with Tx = {int, long int, void}]’ evaluated to ‘false’ instead of cpp2a/concepts-pr67719.C:9:8: note: the expression ‘(... &&(C<Tx>)())’ evaluated to ‘false’ Tested on x86_64-pc-linux-gnu, and verified that all the diagnostics emitted in our concept tests are no worse with this patch. gcc/cp/ChangeLog: * constraint.cc (finish_constraint_binary_op): Set expr's location range to the range of its operands. (satisfy_atom): Pass MAP instead of ARGS to diagnose_atomic_constraint. (diagnose_trait_expr): Take the instantiated parameter mapping MAP instead of the corresponding template arguments ARGS and adjust body accordingly. (diagnose_requires_expr): Likewise. (diagnose_atomic_constraint): Likewise. When printing an atomic constraint expression, print the instantiated parameter mapping alongside it. * cxx-pretty-print.cc (cxx_pretty_printer::expression) [NONTYPE_ARGUMENT_PACK]: Print braces around a NONTYPE_ARGUMENT_PACK. (cxx_pretty_printer::type_id): Handle TYPE_ARGUMENT_PACK. gcc/testsuite/ChangeLog: * g++.dg/concepts/diagnostic2.C: New test. * g++.dg/concepts/diagnostic3.C: New test.
2020-02-26c++: Fix value-init crash in template [PR93676]Marek Polacek2-2/+11
Since <https://gcc.gnu.org/ml/gcc-patches/2015-02/msg00556.html> we attempt to value-initialize in build_vec_init even when there's no initializer but the type has a constexpr default constructor. But build_value_init doesn't work in templates, and build_vec_init creates a lot of garbage that would not be used anyway, so don't call it in a template. PR c++/93676 - value-init crash in template. * init.c (build_new_1): Don't call build_vec_init in a template. * g++.dg/cpp0x/nsdmi-template19.C: New test.
2020-02-26c++: Fix ICE with static_cast when converting from int[] [PR93862]Marek Polacek4-3/+11
This ICEs since my patch for P0388, which allowed conversions to arrays of unknown bound, but not the reverse, so these two static_casts are ill-formed. [expr.static.cast]/3 says that "cv1 T1" and "cv2 T2" have to be reference-compatible and the comment in build_static_cast_1 says it too but then we actually use reference_related_p... Fixed thus. 2020-02-26 Marek Polacek <polacek@redhat.com> PR c++/93862 - ICE with static_cast when converting from int[]. * call.c (reference_compatible_p): No longer static. * cp-tree.h (reference_compatible_p): Declare. * typeck.c (build_static_cast_1): Use reference_compatible_p instead of reference_related_p. * g++.dg/cpp0x/rv-cast7.C: New test.
2020-02-26c++: Fix ICE with constexpr init and [[no_unique_address]] [PR93803]Marek Polacek2-9/+13
Here we crash when constexpr-initializing a class member of empty class type with [[no_unique_address]]. Without the attribute we would have a ctor (that initializes bar) of the form { .D.2173 = { .x = {} } } but with the attribute reduced_constant_expression_p gets { .x = {} } That means that "idx != field" is true for the latter and we see that foo, the base class of bar, is an empty class, so we want to look at the next initializable field (since empty class fields may not have an initializer). But in this case there are no more, therefore accessing DECL_CHAIN (field) crashes. Long story short, we need to avoid a crash on a null field when we're initializing a class that only contains an empty base class. While poking into this I discovered c++/93898, but that's a different problem. 2020-02-26 Marek Polacek <polacek@redhat.com> PR c++/93803 - ICE with constexpr init and [[no_unique_address]]. * constexpr.c (reduced_constant_expression_p): Don't crash on a null field. * g++.dg/cpp2a/constexpr-init16.C: New test. * g++.dg/cpp2a/constexpr-init17.C: New test.
2020-02-24Remove a hunk duplicated during a merge.Martin Sebor2-7/+1
gcc/cp/ChangeLog: * parser.c (cp_parser_check_class_key): Remove a duplicate hunk of code.
2020-02-24PR c++/93804 - exempt extern C headers from -Wredundant-tagsMartin Sebor2-12/+58
gcc/cp/ChangeLog: PR c++/93804 * parser.c (cp_parser_check_class_key): Avoid issuing -Wredundant-tags in shared C/C++ code in headers. gcc/testsuite/ChangeLog: PR c++/93804 * g++.dg/warn/Wredundant-tags-4.C: New test. * g++.dg/warn/Wredundant-tags-5.C: New test. * g++.dg/warn/Wredundant-tags-5.h: New test.
2020-02-24c++: Fix ICE with -Wmismatched-tags [PR93869]Marek Polacek2-7/+12
This is a crash in cp_parser_check_class_key: tree type_decl = TYPE_MAIN_DECL (type); tree name = DECL_NAME (type_decl); // HERE because TYPE_MAIN_DECL of type was null as it's not a class type. Instead of checking CLASS_TYPE_P we should simply check class_key a bit earlier (in this case it was typename_type). 2020-02-24 Marek Polacek <polacek@redhat.com> PR c++/93869 - ICE with -Wmismatched-tags. * parser.c (cp_parser_check_class_key): Check class_key earlier. * g++.dg/warn/Wmismatched-tags-2.C: New test.
2020-02-24c++: Fix ICE with ill-formed array list-initialization [PR93712]Marek Polacek2-8/+18
My P0388R4 patch changed build_array_conv to create an identity conversion at the start of the conversion chain and now we crash in convert_like_real: 7457 case ck_identity: 7458 if (BRACE_ENCLOSED_INITIALIZER_P (expr)) 7459 { 7460 int nelts = CONSTRUCTOR_NELTS (expr); 7461 if (nelts == 0) 7462 expr = build_value_init (totype, complain); 7463 else if (nelts == 1) 7464 expr = CONSTRUCTOR_ELT (expr, 0)->value; 7465 else 7466 gcc_unreachable (); // HERE 7467 } in a test like this int f (int const (&)[2]) { return f({1, "M"}); } Instead of creating a ck_identity at the start of the conversion chain, so that conv_get_original_expr can be used with a ck_aggr, let's set u.expr for a ck_aggr, and adjust next_conversion not to try to see what's next in the chain if it gets a ck_aggr. 2020-02-24 Marek Polacek <polacek@redhat.com> PR c++/93712 - ICE with ill-formed array list-initialization. * call.c (next_conversion): Return NULL for ck_aggr. (build_aggr_conv): Set u.expr instead of u.next. (build_array_conv): Likewise. (build_complex_conv): Likewise. (conv_get_original_expr): Handle ck_aggr. * g++.dg/cpp0x/initlist-array11.C: New test.
2020-02-24c++: P1937R2 - Fixing inconsistencies between const{expr,eval} functionsJakub Jelinek2-0/+8
The following patch implements my understanding of P1937R2, though I wonder if https://eel.is/c++draft/expr.const#14.example-1 shouldn't have been also either removed or adjusted by the P1937R2 paper. 2020-02-24 Jakub Jelinek <jakub@redhat.com> P1937R2 - Fixing inconsistencies between const{expr,eval} functions * call.c (build_over_call): Don't evaluate immediate functions in unevaluated operands. * g++.dg/ext/consteval1.C: Change dg-{message,error} into dg-bogus. * g++.dg/cpp2a/consteval6.C: Likewise. * g++.dg/cpp2a/consteval3.C: Change dg-error for unevaluated operands into dg-bogus.
2020-02-24c++: Fix C++20 variadic lambda init-capture grammar.Jason Merrill2-2/+19
The grammar for variadic init-capture was fixed at the Prague C++ meeting where we finalized C++20. gcc/cp/ChangeLog 2020-02-24 Jason Merrill <jason@redhat.com> P0780R2: Resolve lambda init-capture pack grammar. * parser.c (cp_parser_lambda_introducer): Expect &...x=y rather than ...&x=y.
2020-02-22c++: Use %qs in diagnostic message [PR93882]Marek Polacek2-1/+6
A tweak for translators, as requested in the PR. 2020-02-22 Marek Polacek <polacek@redhat.com> PR c++/93882 * decl.c (grokdeclarator): Use %qs in a diagnostic message.
2020-02-21PR c++/93753 - ICE on a flexible array followed by a member in an anonymous ↵Martin Sebor2-0/+8
struct with an initializer gcc/cp/ChangeLog: PR gcov-profile/93753 * class.c (check_flexarrays): Tighten up a test for potential members of anonymous structs or unions. gcc/testsuite/ChangeLog: PR gcov-profile/93753 * g++.dg/ext/flexary36.C: New test. * g++.dg/lto/pr93166_0.C: Make struct with flexarray valid.
2020-02-20PR c++/93801 - False -Wmismatched-tags upon redundant typenameMartin Sebor2-0/+12
gcc/cp/ChangeLog: PR c++/93801 * parser.c (cp_parser_check_class_key): Only handle true C++ class-keys. gcc/testsuite/ChangeLog: PR c++/93801 * g++.dg/warn/Wredundant-tags-3.C: New test.
2020-02-20Remove superfluous word in documentation.Martin Liska1-0/+6
PR translation/93841 * config/or1k/or1k.opt: Remove superfluous word. * doc/invoke.texi: Likewise.
2020-02-20Remove triling space for a warning.Martin Liska2-1/+6
PR translation/93838 * parser.c (cp_parser_decl_specifier_seq): Remove trailing space.
2020-02-19c++: Fix wrong-code with non-constexpr constructor [PR93169]Marek Polacek2-1/+8
In order to detect modifying constant objects in constexpr evaluation, which is UB, in r10-2655 I added code that sets TREE_READONLY on CONSTRUCTORs of const-qualified objects after they have been fully constructed. But I never made sure that what we're setting the flag on actually is a CONSTRUCTOR. Consequently, as this test case shows, we could set TREE_READONLY on a VAR_DECL that in fact wasn't constant, causing problems later. Fixed by setting the flag on CONSTRUCTORs only, and only when the evaluation produced something constant. 2020-02-19 Marek Polacek <polacek@redhat.com> PR c++/93169 - wrong-code with a non-constexpr constructor. * constexpr.c (cxx_eval_call_expression): Only set TREE_READONLY on constant CONSTRUCTORs. * g++.dg/cpp0x/constexpr-93169.C: New test.
2020-02-15c++: Fix poor diagnostic for array initializer [PR93710]Marek Polacek2-2/+9
A small improvement for an error in build_user_type_conversion_1: instead of array-init1.C:11:1: error: conversion from ‘long int’ to ‘A’ is ambiguous 11 | }; | ^ we will print array-init1.C:8:3: error: conversion from ‘long int’ to ‘A’ is ambiguous 8 | 0L, | ^~ 2020-02-12 Marek Polacek <polacek@redhat.com> PR c++/93710 - poor diagnostic for array initializer. * call.c (build_user_type_conversion_1): Use cp_expr_loc_or_input_loc for an error call. * g++.dg/diagnostic/array-init1.C: New test.
2020-02-15c++: Fix lambda in atomic constraint.Jason Merrill2-0/+12
find_template_parameters needs to find the mention of T in the lambda. Fixing that leaves this as a hard error, which may be surprising but is consistent with lambdas in other SFINAE contexts like template argument deduction. gcc/cp/ChangeLog 2020-02-15 Jason Merrill <jason@redhat.com> PR c++/92556 * pt.c (any_template_parm_r): Look into lambda body.
2020-02-15c++: Remove more dead code.Jason Merrill2-5/+5
gcc/cp/ChangeLog 2020-02-15 Jason Merrill <jason@redhat.com> PR c++/92583 * pt.c (any_template_parm_r): Remove CONSTRUCTOR handling.
2020-02-14c++: Fix thinko in enum_min_precision [PR61414]Jakub Jelinek2-1/+4
When backporting the PR61414 fix to 8.4, I've noticed that the caching of prec is actually broken, as it would fail to actually store the computed precision into the hash_map's value and so next time we'd think the enum needs 0 bits. 2020-02-14 Jakub Jelinek <jakub@redhat.com> PR c++/61414 * class.c (enum_min_precision): Change prec type from int to int &. * g++.dg/cpp0x/enum39.C: New test.
2020-02-14c++: Emit DFP typeinfos even when DFP is disabled [PR92906]Jakub Jelinek4-3/+39
Before Joseph's changes when compiling libstdc++-v3/libsupc++/fundamental_type_info.cc we were emitting _ZTIPDd, _ZTIPDe, _ZTIPDf, _ZTIPKDd, _ZTIPKDe, _ZTIPKDf, _ZTIDd, _ZTIDe, _ZTIDf symbols even when DFP wasn't usable, but now we don't and thus those 9 symbols @@CXXABI_1.3.4 are gone from libstdc++. While nothing could probably use it (except perhaps dlsym etc.), various tools don't really like symbols disappearing from symbol versioned shared libraries with stable ABI. Adding those in assembly would be possible, but would be a portability nightmare (the PR has something Red Hat uses in libstdc++_nonshared.a, but that can handle only a handful of linux ELF targets we care about). So, instead this patch hacks up the FE, so that it emits those, but in a way that won't make the DFP types available again on targets that don't support them. 2020-02-14 Jakub Jelinek <jakub@redhat.com> PR libstdc++/92906 * cp-tree.h (enum cp_tree_index): Add CPTI_FALLBACK_DFLOAT32_TYPE, CPTI_FALLBACK_DFLOAT64_TYPE and CPTI_FALLBACK_DFLOAT128_TYPE. (fallback_dfloat32_type, fallback_dfloat64_type, fallback_dfloat128_type): Define. * mangle.c (write_builtin_type): Handle fallback_dfloat*_type like dfloat*_type_node. * rtti.c (emit_support_tinfos): Emit DFP typeinfos even when dfp is disabled for compatibility.
2020-02-13c++: Fix useless using-declaration.Jason Merrill2-2/+8
Here reintroducing the same declarations into the global namespace via using-declaration is useless but OK. And a function and a function template with the same parameters do not conflict. gcc/cp/ChangeLog 2020-02-13 Jason Merrill <jason@redhat.com> PR c++/93713 * name-lookup.c (matching_fn_p): A function does not match a template.
2020-02-13c++: Fix static local vars in extern "C".Jason Merrill2-5/+10
Since my patch for PR 91476 moved visibility determination sooner, a local static in a vague linkage function now gets TREE_PUBLIC set before retrofit_lang_decl calls set_decl_linkage, which was making decl_linkage think that it has external linkage. It still has no linkage according to the standard. gcc/cp/ChangeLog 2020-02-13 Jason Merrill <jason@redhat.com> PR c++/93643 PR c++/91476 * tree.c (decl_linkage): Always lk_none for locals.
2020-02-13c++: Fix constexpr if and braced functional cast.Jason Merrill3-3/+12
While partially instantiating a generic lambda, we can encounter pack expansions or constexpr if where we can't actually do the substitution immediately, and instead remember a partial instantiation context in *_EXTRA_ARGS. This includes any local_specializations used in the pattern or condition. In this testcase our tree walk wasn't finding the use of i because we weren't walking into the type of a CONSTRUCTOR. Fixed by moving the code for doing that from find_parameter_packs_r into cp_walk_subtrees. 2020-02-11 Jason Merrill <jason@redhat.com> PR c++/92583 PR c++/92654 * tree.c (cp_walk_subtrees): Walk CONSTRUCTOR types here. * pt.c (find_parameter_packs_r): Not here.
2020-02-12coroutines: Update to n4849 allocation/deallocation.Iain Sandoe2-75/+180
This updates the coroutine frame allocation and deallocation usage to match n4849. [dcl.fct.def.coroutine] /9, /10, /12. 9 An implementation may need to allocate additional storage for a coroutine. This storage is known as the coroutine state and is obtained by calling a non-array allocation function. The allocation function’s name is looked up in the scope of the promise type. If this lookup fails, the allocation function’s name is looked up in the global scope. If the lookup finds an allocation function in the scope of the promise type, overload resolution is performed on a function call created by assembling an argument list. The first argument is the amount of space requested, and has type std::size_t. The lvalues p1 . . . pn are the succeeding [user's function] arguments. If no viable function is found, overload resolution is performed again on a function call created by passing just the amount of space required as an argument of type std::size_t. 10 The unqualified-id get_return_object_on_allocation_failure is looked up in the scope of the promise type by class member access lookup. If any declarations are found, then the result of a call to an allocation function used to obtain storage for the coroutine state is assumed to return nullptr if it fails to obtain storage, and if a global allocation function is selected, the ::operator new(size_t, nothrow_t) form is used. The allocation function used in this case shall have a non-throwing noexcept-specification. If the allocation function returns nullptr, the coroutine returns control to the caller of the coroutine and the return value is obtained by a call to T::get_return_object_on_allocation_failure(), where T is the promise type. 12 The deallocation function’s name is looked up in the scope of the promise type. If this lookup fails, the deallocation function’s name is looked up in the global scope. If deallocation function lookup finds both a usual deallocation function with only a pointer parameter and a usual deallocation function with both a pointer parameter and a size parameter, then the selected deallocation function shall be the one with two parameters. Otherwise, the selected deallocation function shall be the function with one parameter. If no usual deallocation function is found, the program is ill- formed. The selected deallocation function shall be called with the address of the block of storage to be reclaimed as its first argument. If a deallocation function with a parameter of type std::size_t is used, the size of the block is passed as the corresponding argument. gcc/cp/ChangeLog: 2020-02-12 Iain Sandoe <iain@sandoe.co.uk> * coroutines.cc (build_actor_fn): Implement deallocation function selection per n4849, dcl.fct.def.coroutine bullet 12. (morph_fn_to_coro): Implement allocation function selection per n4849, dcl.fct.def.coroutine bullets 9 and 10. 2020-02-12 Iain Sandoe <iain@sandoe.co.uk> * g++.dg/coroutines/coro1-allocators.h: New. * g++.dg/coroutines/coro-bad-alloc-00-bad-op-new.C: New test. * g++.dg/coroutines/coro-bad-alloc-01-bad-op-del.C: New test. * g++.dg/coroutines/coro-bad-alloc-02-no-op-new-nt.C: New test. * g++.dg/coroutines/torture/alloc-00-gro-on-alloc-fail.C: Use new coro1-allocators.h header. * g++.dg/coroutines/torture/alloc-01-overload-newdel.C: Likewise. * g++.dg/coroutines/torture/alloc-02-fail-new-grooaf-check.C: New. * g++.dg/coroutines/torture/alloc-03-overload-new-1.C: New test. * g++.dg/coroutines/torture/alloc-04-overload-del-use-two-args.C:New.
2020-02-12c++: Fix ICE-on-invalid with broken attribute [PR93684]Marek Polacek2-1/+8
We crash when parsing [[a:: because we see a CPP_SCOPE and then we're trying to consume a CPP_EOF token. So peek before consuming it. PR c++/93684 - ICE-on-invalid with broken attribute. * parser.c (cp_parser_std_attribute): Peek a token first before consuming it. * g++.dg/parse/attr4.C: New test.
2020-02-12c++: Fix implicit friend operator==.Jason Merrill5-11/+54
It seems that in writing testcases for the operator<=> proposal I didn't include any tests for implicitly declared friend operator==, and consequently it didn't work. 2020-02-11 Jason Merrill <jason@redhat.com> PR c++/93675 * class.c (add_implicitly_declared_members): Use do_friend. * method.c (implicitly_declare_fn): Fix friend handling. (decl_remember_implicit_trigger_p): New. (synthesize_method): Use it. * decl2.c (mark_used): Use it.
2020-02-11c++: Fix static initialization from <=>.Jason Merrill3-7/+16
Constant evaluation of genericize_spaceship produced a CONSTRUCTOR, which we then wanted to bind to a reference, which we can't do. So wrap the result in a TARGET_EXPR so we get something with an address. We also need to handle treating the result of cxx_eval_binary_expression as a glvalue for SPACESHIP_EXPR. My earlier change to add uid_sensitive to maybe_constant_value was wrong; we don't even look at the cache when manifestly_const_eval, and I failed to adjust the later call to cxx_eval_outermost_constant_expr. gcc/cp/ChangeLog 2020-02-11 Jason Merrill <jason@redhat.com> PR c++/93650 PR c++/90691 * constexpr.c (maybe_constant_value): Correct earlier change. (cxx_eval_binary_expression) [SPACESHIP_EXPR]: Pass lval through. * method.c (genericize_spaceship): Wrap result in TARGET_EXPR.
2020-02-10c++: Fix return type deduction with an abbreviated function templatePatrick Palka4-26/+44
This patch fixes two issues with return type deduction in the presence of an abbreviated function template. The first issue (PR 69448) is that if a placeholder auto return type contains any modifiers such as & or *, then the abbreviated function template compensation in splice_late_return_type does not get performed for the underlying auto node, leading to incorrect return type deduction. This happens because splice_late_return_type does not consider that a placeholder auto return type might have modifiers. To fix this it seems we need to look through modifiers in the return type to obtain the location of the underlying auto node in order to replace it with the adjusted auto node. To that end this patch refactors the utility function find_type_usage to return a pointer to the matched tree, and uses it to find and replace the underlying auto node. The second issue (PR 80471) is that the AUTO_IS_DECLTYPE flag is not being preserved in splice_late_return_type when compensating for an abbreviated function template, leading to us treating a decltype(auto) return type as if it was an auto return type. Fixed by making make_auto_1 set the AUTO_IS_DECLTYPE flag whenever we're building a decltype(auto) node and adjusting callers appropriately. The test for PR 80471 is adjusted to expect the correct behavior. gcc/cp/ChangeLog: PR c++/69448 PR c++/80471 * type-utils.h (find_type_usage): Refactor to take a tree * and to return a tree *, and update documentation accordingly. * pt.c (make_auto_1): Set AUTO_IS_DECLTYPE when building a decltype(auto) node. (make_constrained_decltype_auto): No need to explicitly set AUTO_IS_DECLTYPE anymore. (splice_late_return_type): Use find_type_usage to find and replace a possibly nested auto node instead of using is_auto. Check test for is_auto into an assert when deciding whether to late_return_type. (type_uses_auto): Adjust the call to find_type_usage. * parser.c (cp_parser_decltype): No need to explicitly set AUTO_IS_DECLTYPE anymore. libcc1/ChangeLog: PR c++/69448 PR c++/80471 * libcp1plugin.cc (plugin_get_expr_type): No need to explicitly set AUTO_IS_DECLTYPE anymore. gcc/testsuite/ChangeLog: PR c++/69448 PR c++/80471 * g++.dg/concepts/abbrev3.C: New test. * g++.dg/cpp2a/concepts-pr80471.C: Adjust a static_assert to expect the correct behavior. * g++.dg/cpp0x/auto9.C: Adjust a dg-error directive.
2020-02-10c++: Improve dump_decl for standard conceptsPatrick Palka2-10/+14
This patch improves the pretty printing of standard concept definitions in error messages. In particular, standard concepts are now printed qualified whenever appropriate, and the "concept" specifier is printed only when the TFF_DECL_SPECIFIERS flag is specified. In the below test, the first error message changes from 9:15: error: ‘b’ was not declared in this scope; did you mean ‘concept b’? to 9:15: error: ‘b’ was not declared in this scope; did you mean ‘a::b’? gcc/cp/ChangeLog: * error.c (dump_decl) [CONCEPT_DECL]: Use dump_simple_decl. (dump_simple_decl): Handle standard concept definitions as well as variable concept definitions. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts6.C: New test.
2020-02-10c++: Fux strncmp last argument in dump_decl_name [PR93641]Jakub Jelinek2-1/+6
I'm not aware of symbols starting with _ZG that don't start with _ZGR prefix, but perhaps in the future there might be some. 2020-02-10 Jakub Jelinek <jakub@redhat.com> PR other/93641 * error.c (dump_decl_name): Fix up last argument to strncmp.
2020-02-10c++: Fix flexible array with synthesized constructor.Jason Merrill4-2/+21
We were already rejecting initialization of a flexible array member in a constructor; we similarly shouldn't try to clean it up. PR c++/93618 * tree.c (array_of_unknown_bound_p): New. * init.c (perform_member_init): Do nothing for flexible arrays.