aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
AgeCommit message (Collapse)AuthorFilesLines
2020-08-01Daily bump.GCC Administrator1-0/+40
2020-07-31c++: Use error_at rather than warning_at for missing return in constexpr ↵Jakub Jelinek1-38/+45
functions [PR96182] For C++11 we already emit an error if a constexpr function doesn't contain a return statement, because in C++11 that is the only thing it needs to contain, but for C++14 we would normally issue a -Wreturn-type warning. As mentioned by Jonathan, such constexpr functions are invalid, no diagnostics required, because there doesn't exist any arguments for which it would result in valid constant expression. This raises it to an error in such cases. The !LAMBDA_TYPE_P case is to avoid error on g++.dg/pr81194.C where the user didn't write constexpr anywhere and the operator() is compiler generated. 2020-07-31 Jakub Jelinek <jakub@redhat.com> PR c++/96182 * decl.c (finish_function): In constexpr functions use for C++14 and later error instead of warning if no return statement is present and diagnose it regardless of warn_return_type. Move the warn_return_type diagnostics earlier in the function. * g++.dg/cpp1y/constexpr-96182.C: New test. * g++.dg/other/error35.C (S<T>::g()): Add return statement. * g++.dg/cpp1y/pr63996.C (foo): Likewise. * g++.dg/cpp1y/constexpr-return2.C (f): Likewise. * g++.dg/cpp1y/var-templ44.C (make_array): Add throw 1.
2020-07-31Set and test no-warning bit to avoid -Wnonnull for synthesized expressions.Martin Sebor1-2/+8
Resolves: PR c++/96003 spurious -Wnonnull calling a member on the result of static_cast gcc/c-family/ChangeLog: PR c++/96003 * c-common.c (check_function_arguments_recurse): Return early when no-warning bit is set. gcc/cp/ChangeLog: PR c++/96003 * class.c (build_base_path): Set no-warning bit on the synthesized conditional expression in static_cast. gcc/testsuite/ChangeLog: PR c++/96003 * g++.dg/warn/Wnonnull7.C: New test.
2020-07-31debug/96383 - emit debug info for used external functionsRichard Biener1-0/+2
This makes sure to emit full declaration DIEs including formal parameters for used external functions. This helps debugging when debug information of the external entity is not available and also helps external tools cross-checking ABI compatibility which was the bug reporters use case. For cc1 this affects debug information size as follows: VM SIZE FILE SIZE ++++++++++++++ GROWING ++++++++++++++ [ = ] 0 .debug_info +1.63Mi +1.3% [ = ] 0 .debug_str +263Ki +3.4% [ = ] 0 .debug_abbrev +101Ki +4.9% [ = ] 0 .debug_line +5.71Ki +0.0% +44% +16 [Unmapped] +48 +1.2% -------------- SHRINKING -------------- [ = ] 0 .debug_loc -213 -0.0% -0.0% -48 .text -48 -0.0% [ = ] 0 .debug_ranges -16 -0.0% -0.0% -32 TOTAL +1.99Mi +0.6% and DWARF compression via DWZ can only shave off minor bits here. Previously we emitted no DIEs for external functions at all unless they were referenced via DW_TAG_GNU_call_site which for some GCC revs caused a regular DIE to appear and since GCC 4.9 only a stub without formal parameters. This means at -O0 we did not emit any DIE for external functions but with optimization we emitted stubs. 2020-07-30 Richard Biener <rguenther@suse.de> PR debug/96383 * langhooks-def.h (lhd_finalize_early_debug): Declare. (LANG_HOOKS_FINALIZE_EARLY_DEBUG): Define. (LANG_HOOKS_INITIALIZER): Amend. * langhooks.c: Include cgraph.h and debug.h. (lhd_finalize_early_debug): Default implementation from former code in finalize_compilation_unit. * langhooks.h (lang_hooks::finalize_early_debug): Add. * cgraphunit.c (symbol_table::finalize_compilation_unit): Call the finalize_early_debug langhook. gcc/c-family/ * c-common.h (c_common_finalize_early_debug): Declare. * c-common.c: Include debug.h. (c_common_finalize_early_debug): finalize_early_debug langhook implementation generating debug for extern declarations. gcc/c/ * c-objc-common.h (LANG_HOOKS_FINALIZE_EARLY_DEBUG): Define to c_common_finalize_early_debug. gcc/cp/ * cp-objcp-common.h (LANG_HOOKS_FINALIZE_EARLY_DEBUG): Define to c_common_finalize_early_debug. gcc/testsuite/ * gcc.dg/debug/dwarf2/pr96383-1.c: New testcase. * gcc.dg/debug/dwarf2/pr96383-2.c: Likewise. libstdc++-v3/ * testsuite/20_util/assume_aligned/3.cc: Use -g0.
2020-07-30c++: decl_constant_value and unsharing [PR96197]Patrick Palka3-14/+27
In the testcase from the PR we're seeing excessive memory use (> 5GB) during constexpr evaluation, almost all of which is due to the call to decl_constant_value in the VAR_DECL/CONST_DECL branch of cxx_eval_constant_expression. We reach here every time we evaluate an ARRAY_REF of a constexpr VAR_DECL, and from there decl_constant_value makes an unshared copy of the VAR_DECL's initializer. But unsharing here is unnecessary because callers of cxx_eval_constant_expression already unshare its result when necessary. To fix this excessive unsharing, this patch adds a new defaulted parameter unshare_p to decl_really_constant_value and decl_constant_value so that callers can control whether to unshare. As a simplification, we can also move the call to unshare_expr in constant_value_1 outside of the loop, since doing unshare_expr on a DECL_P is a no-op. Now that we no longer unshare the result of decl_constant_value and decl_really_constant_value from cxx_eval_constant_expression, memory use during constexpr evaluation for the testcase from the PR falls from ~5GB to 15MB according to -ftime-report. gcc/cp/ChangeLog: PR c++/96197 * constexpr.c (cxx_eval_constant_expression) <case CONST_DECL>: Pass false to decl_constant_value and decl_really_constant_value so that they don't unshare their result. * cp-tree.h (decl_constant_value): New declaration with an added bool parameter. (decl_really_constant_value): Add bool parameter defaulting to true to existing declaration. * init.c (constant_value_1): Add bool parameter which controls whether to unshare the initializer before returning. Call unshare_expr at most once. (scalar_constant_value): Pass true to constant_value_1's new bool parameter. (decl_really_constant_value): Add bool parameter and forward it to constant_value_1. (decl_constant_value): Likewise, but instead define a new overload with an added bool parameter. gcc/testsuite/ChangeLog: PR c++/96197 * g++.dg/cpp1y/constexpr-array8.C: New test.
2020-07-31Daily bump.GCC Administrator1-0/+28
2020-07-29c++: overload sets and placeholder return type [PR64194]Patrick Palka1-1/+10
In the testcase below, template argument deduction for the call g(id<int>) goes wrong because the functions in the overload set id<int> each have a yet-undeduced auto return type, and this undeduced return type makes try_one_overload fail to match up any of the overloads with g's parameter type, leading to g's template argument going undeduced and to the overload set going unresolved. This patch fixes this issue by performing return type deduction via instantiation before doing try_one_overload, in a manner similar to what resolve_address_of_overloaded_function does. gcc/cp/ChangeLog: PR c++/64194 * pt.c (resolve_overloaded_unification): If the function template specialization has a placeholder return type, then instantiate it before attempting unification. gcc/testsuite/ChangeLog: PR c++/64194 * g++.dg/cpp1y/auto-fn60.C: New test.
2020-07-29c++: alias_ctad_tweaks and constrained dguide [PR95486]Patrick Palka1-1/+4
In the below testcase, we're ICEing from alias_ctad_tweaks ultimately because the implied deduction guide for X's user-defined constructor already has constraints associated with it. We then carry over these constraints to 'fprime', the overlying deduction guide for the alias template Y, via tsubst_decl from alias_ctad_tweaks. Later in alias_ctad_tweaks we call get_constraints followed by set_constraints without doing remove_constraints in between, which triggers the !found assert in set_constraints. This patch fixes this issue by adding an intervening call to remove_constraints. gcc/cp/ChangeLog: PR c++/95486 * pt.c (alias_ctad_tweaks): Call remove_constraints before calling set_constraints. gcc/testsuite/ChangeLog: PR c++/95486 * g++.dg/cpp2a/class-deduction-alias3.C: New test.
2020-07-29c++: abbreviated function template friend matching [PR96106]Patrick Palka1-0/+1
In the below testcase, duplicate_decls wasn't merging the tsubsted friend declaration for 'void add(auto)' with its definition, because reduce_template_parm_level (during tsubst_friend_function) lost the DECL_VIRTUAL_P flag on the auto's invented template parameter, which caused template_heads_equivalent_p to deem the two template heads as not equivalent in C++20 mode. This patch makes reduce_template_parm_level carry over the DECL_VIRTUAL_P flag from the original TEMPLATE_PARM_DECL. gcc/cp/ChangeLog: PR c++/96106 * pt.c (reduce_template_parm_level): Propagate DECL_VIRTUAL_P from the original TEMPLATE_PARM_DECL to the new lowered one. gcc/testsuite/ChangeLog: PR c++/96106 * g++.dg/concepts/abbrev7.C: New test.
2020-07-29c++: constraints and explicit instantiation [PR96164]Patrick Palka2-12/+17
When considering to instantiate a member of a class template as part of an explicit instantiation of the class template, we need to first check the member's constraints before proceeding with the instantiation of the member. gcc/cp/ChangeLog: PR c++/96164 * constraint.cc (constraints_satisfied_p): Return true if !flags_concepts. * pt.c (do_type_instantiation): Update a paragraph taken from [temp.explicit] to reflect the latest specification. Don't instantiate a member with unsatisfied constraints. gcc/testsuite/ChangeLog: PR c++/96164 * g++.dg/cpp2a/concepts-explicit-inst5.C: New test.
2020-07-30Daily bump.GCC Administrator1-0/+23
2020-07-29c++: Implement C++20 implicit move changes. [PR91427]Jason Merrill7-63/+144
P1825R0 extends the C++11 implicit move on return by removing the constraints on the called constructor: previously, it needed to take an rvalue reference to the type of the returned variable. The paper also allows move on throw of parameters and implicit move of rvalue references. Discussion on the CWG reflector about how to avoid breaking the PR91212 test in the new model settled on the model of doing only a single overload resolution, with the variable treated as an xvalue that can bind to non-const lvalue references. So this patch implements that approach. The implementation does not use the existing LOOKUP_PREFER_RVALUE flag, but instead sets a flag on the representation of the static_cast turning the variable into an xvalue. For the time being I'm limiting the new semantics to C++20 mode; since it was moved as a DR, we will probably want to apply the change to other standard modes as well once we have a better sense of the impact on existing code, probably in GCC 12. gcc/cp/ChangeLog: PR c++/91427 * cp-tree.h (IMPLICIT_RVALUE_P): New. (enum cp_lvalue_kind_flags): Add clk_implicit_rval. (implicit_rvalue_p, set_implicit_rvalue_p): New. * call.c (reference_binding): Check clk_implicit_rval. (build_over_call): Adjust C++20 implicit move. * coroutines.cc (finish_co_return_stmt): Simplify implicit move. * except.c (build_throw): Adjust C++20 implicit move. * pt.c (tsubst_copy_and_build) [STATIC_CAST_EXPR]: Propagate IMPLICIT_RVALUE_P. * tree.c (lvalue_kind): Set clk_implicit_rval. * typeck.c (treat_lvalue_as_rvalue_p): Overhaul. (maybe_warn_pessimizing_move): Adjust. (check_return_expr): Adjust C++20 implicit move. gcc/testsuite/ChangeLog: PR c++/91427 * g++.dg/coroutines/co-return-syntax-10-movable.C: Extend. * g++.dg/cpp0x/Wredundant-move1.C: Adjust for C++20. * g++.dg/cpp0x/Wredundant-move7.C: Adjust for C++20. * g++.dg/cpp0x/Wredundant-move9.C: Adjust for C++20. * g++.dg/cpp0x/elision_neg.C: Adjust for C++20. * g++.dg/cpp0x/move-return2.C: Adjust for C++20. * g++.dg/cpp0x/ref-qual20.C: Adjust for C++20. * g++.dg/cpp2a/implicit-move1.C: New test. * g++.dg/cpp2a/implicit-move2.C: New test. * g++.dg/cpp2a/implicit-move3.C: New test.
2020-07-29c++: Avoid calling const copy ctor on implicit move. [PR91212]Jason Merrill1-3/+6
Our implementation of C++11 implicit move was wrong for return; we didn't actually hit the check for the type of the first parameter of the selected constructor, because we didn't see LOOKUP_PREFER_RVALUE set properly. Fixing that to look at the right flags fixed the issue for this testcase, but broke implicit move for a by-value converting constructor (PR58051). I think this was not allowed in C++17, but it is allowed under the implicit move changes from C++20, and those changes were voted to apply as a DR to earlier standards as well, so I don't want to break it now. So after fixing the flags check I changed the test to allow value parameters. gcc/cp/ChangeLog: PR c++/91212 * call.c (build_over_call): Don't call a const ref overload for implicit move. gcc/testsuite/ChangeLog: PR c++/91212 * g++.dg/cpp0x/move-return3.C: New test.
2020-07-29Daily bump.GCC Administrator1-0/+29
2020-07-28c++: Set more DECL_CONTEXTsNathan Sidwell3-8/+8
I discovered we were not setting DECL_CONTEXT in a few cases, and grokfndecl's control flow wasn't making it clear that we were doing it in all cases. gcc/cp/ * cp-gimplify.c (cp_genericize_r): Set IMPORTED_DECL's context. * cp-objcp-common.c (cp_pushdecl): Set decl's context. * decl.c (grokfndecl): Make DECL_CONTEXT setting clearer.
2020-07-28c++: better fixup_type_variantsNathan Sidwell1-6/+4
fixup_type_variants was almost doing all that finish_struct needs. May as well make it do it all. gcc/cp/ * class.c (fixup_type_variants): Copy TYPE_SIZE and TYPE_SIZE_UINIT. (finish_struct): Call it.
2020-07-28c++: tree dump indentationNathan Sidwell1-6/+24
We were always forcing an indent, even if there was nothing to indent. Fixed thusly. gcc/cp/ * ptree.c (cxx_print_decl): Better indentation.
2020-07-28c++: Fix up cp_lexer_safe_previous_token [PR96328]Jakub Jelinek1-33/+45
The following testcase ICEs, because cp_lexer_safe_previous_token calls cp_lexer_previous_token and that ICEs, because all tokens in the lexer buffer before the current one (CPP_EOF) have been purged. cp_lexer_safe_previous_token is used in the context where it is ok if it punts, so the patch changes the function so that it doesn't assert there is some previous token, but instead returns NULL like in other cases where it punts. In addition to this, in the last hunk it does a micro-optimization, don't call the potentially expensive function if it will not need the result, instead check the least expensive condition first. And the middle hunk is a similar change from Mark's version of the patch, to use the safe variant in there because it is again just about a hint and it is better not to provide the hint than to ICE, though we don't have a testcase that would ICE. 2020-07-28 Jakub Jelinek <jakub@redhat.com> Mark Wielaard <mark@klomp.org> PR c++/96328 * parser.c (cp_lexer_safe_previous_token): Don't call cp_lexer_previous_token, instead inline it by hand and return NULL instead of failing assertion if all previous tokens until the first one are purged. (cp_parser_error_1): Optimize - only call cp_lexer_safe_previous_token if token->type is CPP_NAME. Use cp_lexer_safe_previous_token instead of cp_lexer_previous_token for the missing_token_desc != RT_NONE case too. * g++.dg/diagnostic/pr96328.C: New test. Co-Authored-By: Mark Wielaard <mark@klomp.org>
2020-07-28Daily bump.GCC Administrator1-0/+9
2020-07-27c++: Name as_base typeNathan Sidwell3-2/+10
The as-base type never got a name. For modules I needed to give it a name to serialize properly, and it's useful when debugging the compiler, so we may as well have it on trunk. There's also a bug where its fields can have NSDMIs from the main class. This happens to be silent on trunk, but can be a GC leak where we retain a deferred parse node there. (On modules it blows up, because we're not prepared to serialize deferred parse nodes, as they should never survive parsing. gcc/cp/ * cp-tree.h (enum cp_tree_index): Add CPTI_AS_BASE_IDENTIFIER. (as_base_identifier): Define. * decl.c (initialize_predifined_identifiers): Initialize as_base identifier. * class.c (layout_class_type): Name the as-base type. Zap NSDMI its fields may have.
2020-07-23Daily bump.GCC Administrator1-0/+42
2020-07-22c++: Don't add enums to class's decl_listNathan Sidwell1-5/+8
We don't need to add CONST_DECLs to a template decl's decl list. Also made the code flow a bit clearer. gcc/cp/ * class.c (maybe_add_class_template_decl_list): Don't add CONST_DECLs.
2020-07-22c++: structural_comptypes additionNathan Sidwell1-9/+15
I had to debug structural_comptypes, and its complex if conditions and tail calling of same_type_p made that hard. I'd hope we can turn the eqivalent of return boolean_fn () ? true : false; into a tail call of the boolean. We also were not dealing with TYPEOF_TYPE. gcc/cp/ * typeck.c (structural_comptypes): [DECLTYPE_TYPE] break apart complex if. [UNDERLYING_TYPE]: Use an if. [TYPEOF_TYPE]: New.
2020-07-22c++: More cleanups for modern C++Nathan Sidwell3-58/+39
Here are some more places where we can declare variables at the assignment point, rather than use C89. Also, let's name our variables by what they contain -- the register allocator is perfectly able to track liveness for us. gcc/cp/ * decl.c (decls_match): Move variables into scopes they're needed in. (duplicate_decls): Use STRIP_TEMPLATE. (build_typename_type): Move var decls to their assignments. (begin_function_body): Likewise. * decl2.c (get_guard): Likewise. (mark_used): Use true for truthiness. * error.c (dump_aggr_type): Hold the decl in a var called 'decl', not 'name'.
2020-07-22c++: Shrink lambda-exprNathan Sidwell1-2/+2
I noticed the default capture mode and the discriminator both used ints. That seems excessive. This shrinks them to 8 bits and 16 bits respectively. I suppose the discriminator could use the remaining 24 bits of an int allocation unit, if we're worried about more that 64K lambdas per function. I know, users are strange :) On a 64 bit system this saves 64 bits, because we also had 32 bits of padding added. gcc/cp/ * cp-tree.h (struct tree_lambda_expr): Shrink default_capture_mode & discriminator.
2020-07-22c++: mangling cleanupsNathan Sidwell1-49/+26
I noticed the mangler's handling of templates could be simplified. We know template_info is non-null, which is sufficiently boolean -- no need for an explicit bool return. also some of the internals of template_args_equal had crept into find_substitution. Let's not do that. gcc/cp/ * mangle.c (decl_is_template_id): Rename to ... (maybe_template_info): ... here. Return the template info, rather than use a pointer. Adjust all callers. (find_substitution): Use template_args_equal, rather than local check.
2020-07-22OpenMP: Fixes for omp critical + hintTobias Burnus2-7/+22
gcc/c-family/ChangeLog: * c-omp.c (c_finish_omp_critical): Check for no name but nonzero hint provided. gcc/c/ChangeLog: * c-parser.c (c_parser_omp_clause_hint): Require nonnegative hint clause. (c_parser_omp_critical): Permit hint(0) clause without named critical. (c_parser_omp_construct): Don't assert if error_mark_node is returned. gcc/cp/ChangeLog: * parser.c (cp_parser_omp_clause_hint): Require nonnegative hint. (cp_parser_omp_critical): Permit hint(0) clause without named critical. * pt.c (tsubst_expr): Re-check the latter for templates. gcc/fortran/ChangeLog: * openmp.c (gfc_match_omp_critical): Fix handling hints; permit hint clause without named critical. (resolve_omp_clauses): Require nonnegative constant integer for the hint clause. (gfc_resolve_omp_directive): Check for no name but nonzero value for hint clause. * parse.c (parse_omp_structured_block): Fix same-name check for critical. * trans-openmp.c (gfc_trans_omp_critical): Handle hint clause properly. libgomp/ChangeLog: * omp_lib.f90.in: Add omp_sync_hint_* and omp_sync_hint_kind. * omp_lib.h.in: Likewise. gcc/testsuite/ChangeLog: * g++.dg/gomp/critical-3.C: Add nameless critical with hint testcase. * c-c++-common/gomp/critical-hint-1.c: New test. * c-c++-common/gomp/critical-hint-2.c: New test. * gfortran.dg/gomp/critical-hint-1.f90: New test. * gfortran.dg/gomp/critical-hint-2.f90: New test.
2020-07-22Daily bump.GCC Administrator1-0/+14
2020-07-21Add TARGET_LOWER_LOCAL_DECL_ALIGNMENT [PR95237]Sunil K Pandey1-0/+7
Default for this hook is NOP. For x86, in 32 bit mode, this hook sets alignment of long long on stack to 32 bits if preferred stack boundary is 32 bits. - This patch prevents lowering of alignment from following macros. LOCAL_ALIGNMENT STACK_SLOT_ALIGNMENT LOCAL_DECL_ALIGNMENT - This patch fixes gcc.target/i386/pr69454-2.c gcc.target/i386/stackalign/longlong-1.c - Regression test on x86-64, no new fail introduced. Tested on x86-64. gcc/c/ChangeLog: PR target/95237 * c-decl.c (finish_decl): Call target hook lower_local_decl_alignment to lower local decl alignment. gcc/ChangeLog: PR target/95237 * config/i386/i386-protos.h (ix86_local_alignment): Add another function parameter may_lower alignment. Default is false. * config/i386/i386.c (ix86_lower_local_decl_alignment): New function. (ix86_local_alignment): Amend ix86_local_alignment to accept another parameter may_lower. If may_lower is true, new align may be lower than incoming alignment. If may_lower is false, new align will be greater or equal to incoming alignment. (TARGET_LOWER_LOCAL_DECL_ALIGNMENT): Define. * doc/tm.texi: Regenerate. * doc/tm.texi.in (TARGET_LOWER_LOCAL_DECL_ALIGNMENT): New hook. * target.def (lower_local_decl_alignment): New hook. gcc/cp/ChangeLog: PR target/95237 * decl.c (cp_finish_decl): Call target hook lower_local_decl_alignment to lower local decl alignment. gcc/testsuite/ChangeLog: PR target/95237 * c-c++-common/pr95237-1.c: New test. * c-c++-common/pr95237-2.c: New test. * c-c++-common/pr95237-3.c: New test. * c-c++-common/pr95237-4.c: New test. * c-c++-common/pr95237-5.c: New test. * c-c++-common/pr95237-6.c: New test. * c-c++-common/pr95237-7.c: New test. * c-c++-common/pr95237-8.c: New test. * c-c++-common/pr95237-9.c: New test.
2020-07-21c++: Fix scan forward over pragma [PR96257]Nathan Sidwell1-8/+9
It turns out that the paren scanning code is used for speculatively searching to see if we're looking at a compound_literal. So we shouldn't always purge pragma tokens. gcc/cp/ * parser.c (cp_lexer_consume_token): Drop PRAGMA_EOL assert. (cp_parser_skip_to_closing_parenthesis_1): Only pass start token to pragma skipper if recovering. (cp_parser_skip_to_pragma_eol): Only purge and change pragma state when recovering. gcc/testsuite/ * g++.dg/parse/pr96257.C: New.
2020-07-21Daily bump.GCC Administrator1-0/+20
2020-07-20c++: Pseudo-destructor ends object lifetime.Jason Merrill2-9/+15
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-20c++: Allow subobject references in C++20.Jason Merrill2-4/+76
The last new thing allowed by P1907R1: subobject addresses as template arguments. The ABI group has discussed mangling for this; there has been some talk of a compressed subobject mangling, but it hasn't been finalized, so for now I'm using normal expression mangling. In order for two array subobject references to compare as equal template arguments, the offsets need to have the same type, so I convert them to always be the same type, currently ptrdiff_t. Base class conversions are represented as a cast to reference type, only if necessary to resolve an ambiguity. This patch also updates the value of __cpp_nontype_template_args, since the paper is fully implemented. gcc/cp/ChangeLog: * mangle.c (write_base_ref): New. (write_expression): Use it for base field COMPONENT_REFs. * pt.c (invalid_tparm_referent_p): Canonicalize the type of array offsets. Allow subobjects. gcc/c-family/ChangeLog: * c-cppbuiltin.c (c_cpp_builtins): Update __cpp_nontype_template_args for C++20. gcc/testsuite/ChangeLog: * g++.dg/cpp1z/nontype2.C: No error in C++20. * g++.dg/template/nontype25.C: No error in C++20. * g++.dg/template/nontype8.C: No error in C++20. * g++.dg/cpp2a/nontype-subob1.C: New test. * g++.dg/cpp2a/nontype-subob2.C: New test. * g++.dg/cpp1z/nontype3.C: Now C++17-only. * g++.dg/cpp2a/feat-cxx2a.C: Adjust expected value.
2020-07-20c++: Aggregate CTAD and string constants.Jason Merrill1-2/+7
In CWG discussion, it was suggested that deduction from a string literal should be to reference-to-const, so that we deduce 'char' rather than 'const char' for T. gcc/cp/ChangeLog: * pt.c (collect_ctor_idx_types): Add 'const' when deducing from a string constant. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/class-deduction-aggr7.C: New test.
2020-07-18Daily bump.GCC Administrator1-0/+6
2020-07-17c++: Diagnose cv-qualified decltype(auto) [PR79815]Marek Polacek2-4/+19
"If the placeholder is the decltype(auto) type-specifier, T shall be the placeholder alone." but we weren't detecting "const decltype(auto)". I've just expanded the existing diagnostic detecting "decltype(auto) &" and similar. gcc/cp/ChangeLog: PR c++/79815 * decl.c (grokdeclarator): Detect cv-qual decltype(auto). * pt.c (do_auto_deduction): Likewise. gcc/testsuite/ChangeLog: PR c++/79815 * g++.dg/cpp1y/auto-fn59.C: New test.
2020-07-17Daily bump.GCC Administrator1-0/+59
2020-07-16coroutines: Correct frame capture of compiler temps [PR95591+4].Iain Sandoe1-474/+654
When a full expression contains a co_await (or co_yield), this means that it might be suspended; which would destroy temporary variables (on a stack for example). However the language guarantees that such temporaries are live until the end of the expression. In order to preserve this, we 'promote' temporaries where necessary so that they are saved in the coroutine frame (which allows them to remain live potentially until the frame is destroyed). In addition, sub-expressions that produce control flow (such as TRUTH_AND/OR_IF or COND_EXPR) must be handled specifically to ensure that await expressions are properly expanded. This patch corrects two mistakes in which we were (a) failing to promote some temporaries and (b) we we failing to sequence DTORs for the captures properly. This manifests in a number of related (but not exact duplicate) PRs. The revised code collects the actions into one place and maps all the control flow into one form - a benefit of this is that co_returns are now expanded earlier (which provides an opportunity to address PR95517 in some future patch). We replace a statement that contains await expression(s) with a bind scope that has a variable list describing the temporaries that have been 'promoted' and a statement list that contains a series of cleanup expressions for each of those. Where we encounter nested conditional expressions, these are wrapped in a try-finally block with a guard var for each sub-expression variable that needs a DTOR. The guards are all declared and initialized to false before the first conditional sub- expression. The 'finally' block contains a series of if blocks (one per guard variable) enclosing the relevant DTOR. Variables listed in a bind scope in this manner are automatically moved to a coroutine frame version by existing code (so we re-use that rather than having a separate mechanism). gcc/cp/ChangeLog: PR c++/95591 PR c++/95599 PR c++/95823 PR c++/95824 PR c++/95895 * coroutines.cc (struct coro_ret_data): Delete. (coro_maybe_expand_co_return): Delete. (co_return_expander): Delete. (expand_co_returns): Delete. (co_await_find_in_subtree): Remove unused name. (build_actor_fn): Remove unused parm, remove handling for co_return expansion. (register_await_info): Demote duplicate info message to a warning. (coro_make_frame_entry): Move closer to use site. (struct susp_frame_data): Add fields for final suspend label and a flag to indicate await expressions with initializers. (captures_temporary): Delete. (register_awaits): Remove unused code, update comments. (find_any_await): New. (tmp_target_expr_p): New. (struct interesting): New. (find_interesting_subtree): New. (struct var_nest_node): New. (flatten_await_stmt): New. (handle_nested_conditionals): New. (process_conditional): New. (replace_statement_captures): Rename to... (maybe_promote_temps): ... this. (maybe_promote_captured_temps): Delete. (analyze_expression_awaits): Check for await expressions with initializers. Simplify handling for truth-and/or-if. (expand_one_truth_if): Simplify (map cases that need expansion to COND_EXPR). (await_statement_walker): Handle CO_RETURN_EXPR. Simplify the handling for truth-and/or-if expressions. (register_local_var_uses): Ensure that we create names in the implementation namespace. (morph_fn_to_coro): Add final suspend label to suspend frame callback data and remove it from the build_actor_fn call. gcc/testsuite/ChangeLog: PR c++/95591 PR c++/95599 PR c++/95823 PR c++/95824 PR c++/95895 * g++.dg/coroutines/pr95591.C: New test. * g++.dg/coroutines/pr95599.C: New test. * g++.dg/coroutines/pr95823.C: New test. * g++.dg/coroutines/pr95824.C: New test.
2020-07-16c++: Get rid of convert_like* macros.Marek Polacek1-73/+86
The convert_like* macros were introduced in 2000-03-05 Nathan Sidwell <nathan@codesourcery.com> * call.c (convert_like): Macrofy. (convert_like_with_context): New macro. but now we can use overloading so we can do away with the macros. I've also taken this chance to rename _real to _internal to make it clear that it should not be called directly. No functional change intended. gcc/cp/ChangeLog: * call.c (convert_like): Remove macro and introduce a new wrapper instead. (convert_like_with_context): Likewise. (convert_like_real): Rename to convert_like. (convert_like_real_1): Rename to convert_like_internal. Call convert_like instead of convert_like_real therein. (perform_direct_initialization_if_possible): Call convert_like instead of convert_like_real.
2020-07-16coroutines: Spelling corrections in comments [NFC].Iain Sandoe1-11/+11
Correct some typos. gcc/cp/ChangeLog: * coroutines.cc: Correct some spelling errors in comments.
2020-07-16Daily bump.GCC Administrator1-0/+16
2020-07-15c++: refactor some parser codeNathan Sidwell1-34/+27
cp_parser_declaration copies tokens to local variables, before inspecting (some of) their fields. There's no need. Just point at them in the token buffer -- they don't move. Also, we never look at the second token if the first is EOF, so no need for some kind of dummy value in that case. gcc/cp/ * parser.c (cp_parser_declaration): Avoid copying tokens. (cp_parser_block_declaration): RAII token pointer.
2020-07-15c++: error recovery & pragmasNathan Sidwell1-15/+32
Parser error recovery can get confused by the tokens within a deferred pragma, as treats those as regular tokens. This adjusts the recovery so that the pragma is treated as a unit. Also, the preprocessor now ensures that we never have an EOF token inside a pragma -- the pragma is always closed first. gcc/cp/ * parser.c (cp_parser_skip_to_closing_parenthesis_1): Deal with meeting a deferred pragma. (cp_parser_skip_to_end_of_statement): Likewise. (cp_parser_skip_to_end_of_block_or_statement): Likewise. (cp_parser_skip_to_pragma_eol): We should never meet EOF. (cp_parser_omp_declare_simd): Likewise. (cp_parser_omp_declare_reduction, cp_parser_oacc_routine) (pragma_lex): Likewise. gcc/testsuite/ * g++.dg/parse/pragma-recovery.C: New.
2020-07-15Daily bump.GCC Administrator1-0/+64
2020-07-14c++: Make convert_like complain about bad ck_ref_bind again [PR95789]Marek Polacek1-16/+38
convert_like issues errors about bad_p conversions at the beginning of the function, but in the ck_ref_bind case, it only issues them after we've called convert_like on the next conversion. This doesn't work as expected since r10-7096 because when we see a conversion from/to class type in a template, we return early, thereby missing the error, and a bad_p conversion goes by undetected. That made the attached test to compile even though it should not. I had thought that I could just move the ck_ref_bind/bad_p errors above to the rest of them, but that regressed diagnostics because expr then wasn't converted yet by the nested convert_like_real call. So, for bad_p conversions, do the normal processing, but still return the IMPLICIT_CONV_EXPR to avoid introducing trees that the template processing can't handle well. This I achieved by adding a wrapper function. gcc/cp/ChangeLog: PR c++/95789 PR c++/96104 PR c++/96179 * call.c (convert_like_real_1): Renamed from convert_like_real. (convert_like_real): New wrapper for convert_like_real_1. gcc/testsuite/ChangeLog: PR c++/95789 PR c++/96104 PR c++/96179 * g++.dg/conversion/ref4.C: New test. * g++.dg/conversion/ref5.C: New test. * g++.dg/conversion/ref6.C: New test.
2020-07-14c++: Parser entry cleanupNathan Sidwell1-51/+44
The handling of PCH is a little trick, because we have to deal with it before allocating memory. I found the layering somewhat confusing. This patch reorganizes that, so that the stopping of PCH is done in exactly one place, and the ordering of lexer creation relative to that is much clearer. I also changed the error message about multiple source files as with C++20, 'modules' means something rather specific. Other than the error message changes, no functional changes. gcc/cp/ * parser.c (cp_lexer_alloc): Do not deal with PCH here. (cp_lexer_new_main): Deal with PCH here. Store the tokens directly into the buffer. (cp_lexer_new_from_tokens): Assert last token isn't purged either. (cp_lexer_get_preprocessor_token): Change first arg to flags, adjust. (cp_parser_new): Pass the lexer in, don't create it here. (cp_parser_translation_unit): Initialize access checks here. (cp_parser_initial_pragma): First token is provided by caller, don't deal with PCH stopping here. Adjust error message. (c_parse_file): Adjust, change error message to avoid C++20 module confusion.
2020-07-14c++: tree dumperNathan Sidwell1-0/+10
A couple of C++ nodes were unknown to the tree dumper. gcc/cp/ * ptree.c (cxx_print_type): Add TYPEOF_TYPE and BASES.
2020-07-14c++: Refactor some class fnsNathan Sidwell1-16/+17
Storing CLASSTYPE_AS_BASE in a local variable makes some code clearer (and textually no longer). For some reason we store a DECL in a variable called 'value', which is confusing. gcc/cp/ * class.c (build_base_field_1): Cache CLASSTYPE_AS_BASE. (build_self_reference): Rename value -> decl. (dump_class_hierarchy_1): Cache CLASSTYPE_AS_BASE.
2020-07-14c++: Improve checking of decls with trailing return type [PR95820]Marek Polacek1-86/+80
This is an ICE-on-invalid but I've been seeing it when reducing various testcases, so it's more important for me than usually. splice_late_return_type now checks that if we've seen a late return type, the function return type was auto. That's a fair assumption but grokdeclarator/cdk_function wasn't giving errors for function pointers and similar. So we want to perform various checks not only when funcdecl_p || inner_declarator == NULL. But only give the !late_return_type errors when funcdecl_p, to accept e.g. auto (*fp)() = f; in C++11. Here's a diff -w to ease the review: --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -12102,14 +12102,9 @@ grokdeclarator (const cp_declarator *declarator, /* Handle a late-specified return type. */ tree late_return_type = declarator->u.function.late_return_type; - if (funcdecl_p - /* This is the case e.g. for - using T = auto () -> int. */ - || inner_declarator == NULL) - { if (tree auto_node = type_uses_auto (type)) { - if (!late_return_type) + if (!late_return_type && funcdecl_p) { if (current_class_type && LAMBDA_TYPE_P (current_class_type)) @@ -12201,7 +12196,6 @@ grokdeclarator (const cp_declarator *declarator, "type specifier", name); return error_mark_node; } - } type = splice_late_return_type (type, late_return_type); if (type == error_mark_node) return error_mark_node; gcc/cp/ChangeLog: PR c++/95820 * decl.c (grokdeclarator) <case cdk_function>: Check also pointers/references/... to functions. gcc/testsuite/ChangeLog: PR c++/95820 * g++.dg/cpp1y/auto-fn58.C: New test.
2020-07-14c++: Comments & formattingNathan Sidwell12-68/+81
I found some bad formatting and misleading or incomplete comments during my spelunking around the c++FE. May as well clean up trunk and record what I noted. gcc/cp/ * cp-tree.h: Correct some tree lang flag comments, reformat some structure definitions. Note some structure sizes. Clarify some comments. (yyungetc): Delete. Not been a thing for some time. * class.c (copy_fndecl_with_name): Comment. (check_bases_and_members): Unnecessary {}. (layout_class_type): Comment. * cp-tree.def (UNBOUND_CLASS_TEMPLATE): Adjust comment. * decl.c: Fix some formatting & whitespace issues. (function_requirements_equivalent_p): Note why substitutions are needed. * decl2.c (no_linkage_error): Note that heroics about 'typedef struct { ... };' are no longer needed. * method.c: Whitespace. * name-lookup.c: Whitespace. (add_decl_to_level): Reformat a line. (print_binding_stack): Mark as DEBUG_FUNCTION. (has_using_namespace_std_directive_p): Delete comment. * pt.c: Whitespace * ptree.c: Whitespace. * rtti.c: Whitespace & comment. * tree.c: Comment. * typeck.c (structural_comptypes): Add comment.