aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/parser.c
AgeCommit message (Collapse)AuthorFilesLines
2020-12-16c++: Fix template parm ICE [PR 98297]Nathan Sidwell1-1/+3
I think this is nonsense code, we seem to be naming an instantiation of a template template parm. But this fixes the ICE. Perhaps we should diagnose the issue earlier? gcc/cp/ * parser.c (cp_parser_elaborated_type_specifier): Test BOUND_TEMPLATE_TEMPLATE_PARM before checking for instantiation. gcc/testsuite/ * g++.dg/template/pr98297.C: New.
2020-12-10c++: Add make_temp_override generator functionsJason Merrill1-4/+4
A common pattern before C++17 is the generator function, used to avoid having to specify the type of a container element by using a function call to get type deduction; for example, std::make_pair. C++17 added class type argument deduction, making generator functions unnecessary for many uses, but GCC won't be written in C++17 for years yet. gcc/cp/ChangeLog: * cp-tree.h (struct type_identity): New. (make_temp_override): New. * decl.c (grokdeclarator): Use it. * except.c (maybe_noexcept_warning): Use it. * parser.c (cp_parser_enum_specifier): Use it. (cp_parser_parameter_declaration_clause): Use it. (cp_parser_gnu_attributes_opt): Use it. (cp_parser_std_attribute): Use it.
2020-12-09c++: Module parsingNathan Sidwell1-5/+386
This adds the module-declaration parsing and other logic. We have two new kinds of declaration -- module and import. Plus the ability to export other declarations. The module processing can also divide the TU into several portions -- GMF, Purview and PMF. There are restrictions that some declarations must or mustnot appear in a #include, so I needed to add a bit to indicate whether a token came from the main source or not. This seemed the least unpleasant way of implementing such a check. gcc/cp/ * parser.h (struct cp_token): Add main_source_p field. * parser.c (cp_lexer_new_main): Pass thought module token filter. Check macros. (cp_lexer_get_preprocessor_token): Set main_source_p. (enum module_parse): New. (cp_parser_diagnose_invalid_type_name): Deal with unrecognized module-directives. (cp_parser_skip_to_closing_parenthesize_1): Skip module-directivres. (cp_parser_skip_to_end_of_statement): Likewise. (cp_parser_skiup_to_end_of_block_or_statement): Likewise. (cp_parser_translation_unit): Add module parsing calls. (cp_parser_module_name, cp_parser_module_declaration): New. (cp_parser_import_declaration, cp_parser_module_export): New. (cp_parser_declaration): Add module export detection. (cp_parser_template_declaration): Adjust 'export' error message. (cp_parser_function_definition_after_declarator): Add module-specific logic. * module.cc (import_module, declare_module) (maybe_check_all_macros): Stubs.
2020-12-09OpenMP: C/C++ parse 'omp allocate'Tobias Burnus1-1/+42
gcc/c-family/ChangeLog: * c-pragma.c (omp_pragmas): Add 'allocate'. * c-pragma.h (enum pragma_kind): Add PRAGMA_OMP_ALLOCATE. gcc/c/ChangeLog: * c-parser.c (c_parser_omp_allocate): New. (c_parser_omp_construct): Call it. gcc/cp/ChangeLog: * parser.c (cp_parser_omp_allocate): New. (cp_parser_omp_construct, cp_parser_pragma): Call it. gcc/testsuite/ChangeLog: * c-c++-common/gomp/allocate-5.c: New test.
2020-12-08openmp: -fopenmp-simd fixes [PR98187]Jakub Jelinek1-0/+3
This patch fixes two bugs in the -fopenmp-simd support. One is that in C++ #pragma omp parallel master would actually create OMP_PARALLEL in the IL, which is a big no-no for -fopenmp-simd, we should be creating only the constructs -fopenmp-simd handles (mainly OMP_SIMD, OMP_LOOP which is gimplified as simd in that case, declare simd/reduction and ordered simd). The other bug was that #pragma omp master taskloop simd combined construct contains simd and thus should be recognized as #pragma omp simd (with only the simd applicable clauses), but as master wasn't included in omp_pragmas_simd, we'd ignore it completely instead. 2020-12-08 Jakub Jelinek <jakub@redhat.com> PR c++/98187 * c-pragma.c (omp_pragmas): Remove "master". (omp_pragmas_simd): Add "master". * parser.c (cp_parser_omp_parallel): For parallel master with -fopenmp-simd only, just call cp_parser_omp_master instead of wrapping it in OMP_PARALLEL. * c-c++-common/gomp/pr98187.c: New test.
2020-12-04vec: Simplify use with C++11 range-based 'for'.Jason Merrill1-5/+1
It looks cleaner if we can use a vec* directly as a range for the C++11 range-based 'for' loop, without needing to indirect from it, and also works with null pointers. The change in cp_parser_late_parsing_default_args is an example of how this can be used to simplify a simple loop over a vector. Reverse or subset iteration will require adding range adaptors. I deliberately didn't format the new overloads for etags since they are trivial. gcc/ChangeLog: * vec.h (begin, end): Add overloads for vec*. * tree.c (build_constructor_from_vec): Remove *. gcc/cp/ChangeLog: * decl2.c (clear_consteval_vfns): Remove *. * pt.c (do_auto_deduction): Remove *. * parser.c (cp_parser_late_parsing_default_args): Change loop to use range 'for'.
2020-12-03c++: Add __builtin_bit_cast to implement std::bit_cast [PR93121]Jakub Jelinek1-0/+26
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-12-02c++: Push parms when late parsing default argsJason Merrill1-6/+26
In this testcase we weren't catching the error in A::f because the parameter 'I' wasn't in scope, so the default argument for 'b' found the global typedef I. Fixed by pushing the parms before parsing. This is a bit complicated because pushdecl clears DECL_CHAIN; do_push_parm_decls deals with this by nreversing first, but that doesn't work here because we only want to push them one at a time; if we pushed all of them before parsing, we'd wrongly reject A::g. gcc/cp/ChangeLog: * parser.c (cp_parser_primary_expression): Distinguish parms from vars in error. (cp_parser_late_parsing_default_args): Pushdecl parms as we go. gcc/testsuite/ChangeLog: * g++.dg/parse/defarg17.C: New test.
2020-12-02c++: Fix late-parsed default arg contextJason Merrill1-0/+4
Jakub noticed that we weren't recognizing a default argument for a consteval member function as being in immediate function context because there was no function parameter scope to look at. Note that this patch doesn't actually push the parameters into the scope, that happens in a separate commit. gcc/cp/ChangeLog: * name-lookup.c (begin_scope): Set immediate_fn_ctx_p. * parser.c (cp_parser_late_parsing_default_args): Push sk_function_parms scope. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/consteval-defarg1.C: New test.
2020-12-01openmp: Avoid ICE on depend clause on depobj OpenMP construct [PR98072]Jakub Jelinek1-0/+2
Since r11-5430 we ICE on the following testcase. When parsing the depobj directive we don't really use cp_parser_omp_all_clauses routine which ATM disables generation of location wrappers and the newly added assertion that there are no location wrappers thus triggers. Fixed by adding the location wrappers suppression sentinel. Longer term, we should handle location wrappers inside of OpenMP clauses. 2020-12-01 Jakub Jelinek <jakub@redhat.com> PR c++/98072 * parser.c (cp_parser_omp_depobj): Suppress location wrappers when parsing depend clause. * c-c++-common/gomp/depobj-2.c: New test.
2020-12-01C++ : Adjust warning for misplaced attributes.Iain Sandoe1-2/+5
This removes the reference to Objective-C++ for the warning that attributes may not be placed before linkage specifications. It also adds a note that they may be placed after that. gcc/cp/ChangeLog: * parser.c (cp_parser_declaration): Add a not about where attributes may be placed.
2020-11-26Don't create location wrapper nodes within OpenACC clausesThomas Schwinge1-2/+17
This fixes a GCC 11, 10, 9 regression introduced by commit dfd7fdca2ac17d8b823a16700525824ca312ade0 (Subversion r267272) "C++: more location wrapper nodes (PR c++/43064, PR c++/43486)". But: this isn't intending to blame David, because back then, the problem hasn't been visible in the testsuite (or else I'm sure would've been addressed right away) because of our all dear friend: missing testsuite coverage. Thus, for GCC 8, I'm likewise enhancing the testsuite, without the C++ front end code changes. I actually had presumed that there may be an issue for OpenACC: <http://mid.mail-archive.com/874lb9qr2u.fsf@euler.schwinge.homeip.net>, so here we are, two years (and many "wasted" hours...) later... gcc/cp/ * parser.c (cp_parser_omp_var_list_no_open): Assert that array section's 'low_bound', 'length' are not location wrapper nodes. (cp_parser_oacc_all_clauses, cp_parser_oacc_cache): Instantiate 'auto_suppress_location_wrappers'. gcc/testsuite/ * c-c++-common/goacc/cache-3-1.c: New. * c-c++-common/goacc/cache-3-2.c: Likewise. * c-c++-common/goacc/data-clause-1.c: Likewise. * c-c++-common/goacc/data-clause-2.c: Likewise. * c-c++-common/gomp/map-1.c: Adjust. * c-c++-common/gomp/map-2.c: Likewise. * g++.dg/goacc/cache-3-1.C: New. * g++.dg/goacc/cache-3-2.C: Likewise. * g++.dg/goacc/data-clause-1.C: Likewise. * g++.dg/goacc/data-clause-2.C: Likewise. * g++.dg/gomp/map-1.C: Adjust. * g++.dg/gomp/map-2.C: Likewise. Reported-by: Sandra Loosemore <sandra@codesourcery.com>
2020-11-25Clean up -Wformat-diag warnings (PR bootstrap/97622, PR bootstrap/94982)Martin Sebor1-2/+4
gcc/c-family/ChangeLog: PR bootstrap/94982 * c-attribs.c (handle_patchable_function_entry_attribute): Avoid -Wformat-diag. gcc/cp/ChangeLog: PR bootstrap/94982 * constraint.cc (debug_argument_list): Avoid -Wformat-diag. * error.c (function_category): Same. (print_template_differences): Same. * logic.cc (debug): Same. * name-lookup.c (lookup_using_decl): Same. * parser.c (maybe_add_cast_fixit): Same. (cp_parser_template_introduction): Same. * typeck.c (access_failure_info::add_fixit_hint): Same. gcc/ChangeLog: PR bootstrap/97622 PR bootstrap/94982 * config/i386/i386-options.c (ix86_valid_target_attribute_inner_p): Avoid -Wformat-diag. * digraph.cc (struct test_edge): Same. * dumpfile.c (dump_loc): Same. (dump_context::begin_scope): Same. * edit-context.c (edited_file::print_diff): Same. (edited_file::print_diff_hunk): Same. * json.cc (object::print): Same. * lto-wrapper.c (merge_and_complain): Same. * reload.c (find_reloads): Same. * tree-diagnostic-path.cc (print_path_summary_as_text): Same. * ubsan.c (ubsan_type_descriptor): Same. gcc/jit/ChangeLog: PR bootstrap/94982 * jit-recording.c (recording::function::dump_to_dot): Avoid -Wformat-diag. (recording::block::dump_to_dot): Same. gcc/testsuite/ChangeLog: PR bootstrap/94982 * c-c++-common/patchable_function_entry-error-3.c: Adjust text of expected warning.
2020-11-21c++: Extend -Wrange-loop-construct for binding-to-temp [PR94695]Marek Polacek1-3/+25
This patch finishes the second half of -Wrange-loop-construct I promised to implement: it warns when a loop variable in a range-based for-loop is initialized with a value of a different type resulting in a copy. For instance: int arr[10]; for (const double &x : arr) { ... } where in every iteration we have to create and destroy a temporary value of type double, to which we bind the reference. This could negatively impact performance. As per Clang, this doesn't warn when the range returns a copy, hence the glvalue_p check. gcc/ChangeLog: PR c++/94695 * doc/invoke.texi: Update the -Wrange-loop-construct description. gcc/cp/ChangeLog: PR c++/94695 * parser.c (warn_for_range_copy): Warn when the loop variable is initialized with a value of a different type resulting in a copy. gcc/testsuite/ChangeLog: PR c++/94695 * g++.dg/warn/Wrange-loop-construct2.C: New test.
2020-11-21c++: Fix ICE-on-invalid with -Wvexing-parse [PR97881]Marek Polacek1-6/+5
This invalid (?) code broke my assumption that if decl_specifiers->type is null, there must be any type-specifiers. Turn the assert into an if to fix this crash. gcc/cp/ChangeLog: PR c++/97881 * parser.c (warn_about_ambiguous_parse): Only assume "int" if we actually saw any type-specifiers. gcc/testsuite/ChangeLog: PR c++/97881 * g++.dg/warn/Wvexing-parse9.C: New test.
2020-11-21c++: Allow template lambdas without lambda-declarator [PR97839]Marek Polacek1-8/+6
Our implementation of template lambdas incorrectly requires the optional lambda-declarator. This was probably required by an early draft of generic lambdas, but now the production is [expr.prim.lambda.general]: lambda-expression: lambda-introducer lambda-declarator [opt] compound-statement lambda-introducer < template-parameter-list > requires-clause [opt] lambda-declarator [opt] compound-statement Therefore, we should accept the following test. gcc/cp/ChangeLog: PR c++/97839 * parser.c (cp_parser_lambda_declarator_opt): Don't require (). gcc/testsuite/ChangeLog: PR c++/97839 * g++.dg/cpp2a/lambda-generic8.C: New test.
2020-11-18Objective-C++ : Avoid ICE on invalid with empty attributes.Iain Sandoe1-2/+2
Empty prefix attributes like: __attribute__ (()) @interface MyClass @end cause an ICE at present, check for that case and skip them. gcc/cp/ChangeLog: * parser.c (cp_parser_objc_valid_prefix_attributes): Check for empty attributes.
2020-11-17C++ : Remove an overzealous checking assert [PR97871]Iain Sandoe1-1/+0
It seems we accept __attribute__(()) without any diagnostic at present, so my added checking assert fires for something like: __attribute__ (()) int a; Fixed by removing the assert; in the case that the user enters something like: __attribute__ (()) extern "C" int foo; The diagnostic about attributes before linkage specs will fire and show the empty attributes. gcc/cp/ChangeLog: PR c++/97871 * parser.c (cp_parser_declaration): Remove checking assert.
2020-11-13c++: Implement C++20 'using enum'. [PR91367]Jason Merrill1-28/+117
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-13[PATCH] Implementation of asm goto outputsVladimir N. Makarov1-2/+1
gcc/ * cfgexpand.c (expand_asm_stmt): Output asm goto with outputs too. Place insns after asm goto on edges. * doc/extend.texi: Reflect the changes in asm goto documentation. * gimple.c (gimple_build_asm_1): Remove an assert checking output absence for asm goto. * gimple.h (gimple_asm_label_op, gimple_asm_set_label_op): Take possible asm goto outputs into account. * ira.c (ira): Remove critical edges for potential asm goto output reloads. (ira_nullify_asm_goto): New function. * ira.h (ira_nullify_asm_goto): New prototype. * lra-assigns.c (lra_split_hard_reg_for): Use ira_nullify_asm_goto. Check that splitting is done inside a basic block. * lra-constraints.c (curr_insn_transform): Permit output reloads for any jump insn. * lra-spills.c (lra_final_code_change): Remove USEs added in ira for asm gotos. * lra.c (lra_process_new_insns): Place output reload insns after jumps in the beginning of destination BBs. * reload.c (find_reloads): Report error for asm gotos with outputs. Modify them to keep CFG consistency to avoid crashes. * tree-into-ssa.c (rewrite_stmt): Don't put debug stmt after asm goto. gcc/c/ * c-parser.c (c_parser_asm_statement): Parse outputs for asm goto too. * c-typeck.c (build_asm_expr): Remove an assert checking output absence for asm goto. gcc/cp * parser.c (cp_parser_asm_definition): Parse outputs for asm goto too. gcc/testsuite/ * c-c++-common/asmgoto-2.c: Permit output in asm goto. * gcc.c-torture/compile/asmgoto-2.c: New. * gcc.c-torture/compile/asmgoto-3.c: New. * gcc.c-torture/compile/asmgoto-4.c: New. * gcc.c-torture/compile/asmgoto-5.c: New.
2020-11-13C-family, Objective-C [1/3] : Implement Wobjc-root-class [PR77404].Iain Sandoe1-1/+2
This warning catches the case that the user has left the superclass specification from a class interface. Root classes are, of course, permitted and an attribute is added to mark these so that the diagnostic is suppressed. The warning and attribute spellings have been kept in sync with the language reference implementation (clang). The diagnostic location information present in the objective-c interface and class definitions is relatively poor. This patch adds a location for the class name to the interface and makes use of it in existing warnings. Part 1 is the changes to code and added tests. Many entries in the testsuite make use of root classes so there are a large number of mechanical changes there adding "-Wno-objc-root-class" to the options. The test changes are parts 2 (objective-c) and 3 (objective-c++) in the patch series. gcc/c-family/ChangeLog: PR objc/77404 * c-attribs.c (handle_objc_root_class_attribute): New * c-objc.h (objc_start_class_interface): Add a location value for the position of the class name. * c.opt: Add Wobjc-root-class. * stub-objc.c (objc_start_class_interface): Add a location value for the position of the class name. gcc/c/ChangeLog: PR objc/77404 * c-parser.c (c_parser_objc_class_definition): Pass the location of the class name to the interface declaration. gcc/cp/ChangeLog: PR objc/77404 * parser.c (cp_parser_objc_class_interface): Pass the location of the class name to the interface declaration. gcc/objc/ChangeLog: PR objc/77404 * objc-act.c (objc_start_class_interface): Accept the location of the class name, use it in existing diagnostic. (start_class): Accept obj_root_class type attributes. Warn when the interface for an implementation does not contain a super class (unless the diagnostic is suppressed by the the command line flag or the objc_root_class type attribute). gcc/testsuite/ChangeLog: PR objc/77404 * objc.dg/attributes/root-class-01.m: New test. * objc.dg/root-class-00.m: New test. * obj-c++.dg/attributes/root-class-01.mm: New test. * obj-c++.dg/root-class-00.mm: New test. gcc/ChangeLog: PR objc/77404 * doc/extend.texi: Document the objc_root_class attribute. * doc/invoke.texi: Document -Wobjc-root-class.
2020-11-11Objective-C++ : Allow prefix attrs on linkage specs.Iain Sandoe1-14/+57
For Objective-C++, this combines prefix attributes from before and after top level linkage specs. The "reference implementation" for Objective-C++ allows this, and system headers depend on it. e.g. __attribute__((__deprecated__)) extern "C" __attribute__((__visibility__("default"))) @interface MyClass ... @end Would consider the list of prefix attributes to the interface for MyClass to include both the visibility and deprecated ones. When we are compiling regular C++, this emits a warning and discards any prefix attributes before a linkage spec. gcc/cp/ChangeLog: * parser.c (cp_parser_declaration): Unless we are compiling for Ojective-C++, warn about and discard any attributes that prefix a linkage specification.
2020-11-11c++: Correct the handling of alignof(expr) [PR88115]Patrick Palka1-2/+2
We're currently neglecting to set the ALIGNOF_EXPR_STD_P flag on an ALIGNOF_EXPR when its operand is an expression. This leads to us handling alignof(expr) as if it were written __alignof__(expr), and returning the preferred alignment instead of the ABI alignment. In the testcase below, this causes the first and third static_assert to fail on x86. gcc/cp/ChangeLog: PR c++/88115 * cp-tree.h (cxx_sizeof_or_alignof_expr): Add bool parameter. * decl.c (fold_sizeof_expr): Pass false to cxx_sizeof_or_alignof_expr. * parser.c (cp_parser_unary_expression): Pass std_alignof to cxx_sizeof_or_alignof_expr. * pt.c (tsubst_copy): Pass false to cxx_sizeof_or_alignof_expr. (tsubst_copy_and_build): Pass std_alignof to cxx_sizeof_or_alignof_expr. * typeck.c (cxx_alignof_expr): Add std_alignof bool parameter and pass it to cxx_sizeof_or_alignof_type. Set ALIGNOF_EXPR_STD_P appropriately. (cxx_sizeof_or_alignof_expr): Add std_alignof bool parameter and pass it to cxx_alignof_expr. Assert op is either SIZEOF_EXPR or ALIGNOF_EXPR. libcc1/ChangeLog: PR c++/88115 * libcp1plugin.cc (plugin_build_unary_expr): Pass true to cxx_sizeof_or_alignof_expr. gcc/testsuite/ChangeLog: PR c++/88115 * g++.dg/cpp0x/alignof6.C: New test.
2020-11-10c++: Improve static_assert diagnostic [PR97518]Marek Polacek1-1/+2
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-0/+9
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-09c++: DR 1914 - Allow duplicate standard attributes.Marek Polacek1-24/+27
Following Joseph's change for C to allow duplicate C2x standard attributes <https://gcc.gnu.org/pipermail/gcc-patches/2020-October/557272.html>, this patch does a similar thing for C++. This is DR 1914, to be resolved by <wg21.link/p2156>, which is not part of the standard yet, but has wide support so looks like a shoo-in. The duplications now produce warnings instead, but only if the attribute wasn't specified via a macro. gcc/c-family/ChangeLog: DR 1914 * c-common.c (attribute_fallthrough_p): Tweak the warning message. gcc/cp/ChangeLog: DR 1914 * parser.c (cp_parser_check_std_attribute): Return bool. Add a location_t parameter. Return true if the attribute wasn't duplicated. Give a warning instead of an error. Check more attributes. (cp_parser_std_attribute_list): Don't add duplicated attributes to the list. Pass location to cp_parser_check_std_attribute. gcc/testsuite/ChangeLog: DR 1914 * c-c++-common/attr-fallthrough-2.c: Adjust dg-warning. * g++.dg/cpp0x/fallthrough2.C: Likewise. * g++.dg/cpp0x/gen-attrs-60.C: Turn dg-error into dg-warning. * g++.dg/cpp1y/attr-deprecated-2.C: Likewise. * g++.dg/cpp2a/attr-likely2.C: Adjust dg-warning. * g++.dg/cpp2a/nodiscard-once.C: Turn dg-error into dg-warning. * g++.dg/cpp0x/gen-attrs-72.C: New test.
2020-11-09c++: Fix -Wvexing-parse ICE with omitted int [PR97762]Marek Polacek1-6/+17
For declarations like long f(); decl_specifiers->type will be NULL, but I neglected to handle this case, therefore we ICE. So handle this case by pretending we've seen 'int', which is good enough for -Wvexing-parse's purposes. gcc/cp/ChangeLog: PR c++/97762 * parser.c (warn_about_ambiguous_parse): Handle the case when there is no type in the decl-specifiers. gcc/testsuite/ChangeLog: PR c++/97762 * g++.dg/warn/Wvexing-parse8.C: New test.
2020-11-09c++: Consistently expose singleton overloadsNathan Sidwell1-5/+0
This is a patch from my name-lookup overhaul. I noticed the parser and one path in name-lookup looked through an overload of a single known decl. It seems more consistent to do that in both paths through name-lookup, and not in the parser itself. gcc/cp/ * name-lookup.c (lookup_qualified_name): Expose an overload of a singleton with known type. (lookup_name_1): Just check the overload's type to expose it. * parser.c (cp_parser_lookup_name): Do not do that check here.
2020-11-08Objective-C/C++ : Handle parsing @property 'class' attribute.Iain Sandoe1-0/+4
This attribute states that a property is one manipulated by class methods (it requires a static variable and the setter and getter must be provided explicitly, they cannot be @synthesized). gcc/c-family/ChangeLog: * c-common.h (OBJC_IS_PATTR_KEYWORD): Add class to the list of keywords accepted in @property attribute contexts. * c-objc.h (enum objc_property_attribute_group): Add OBJC_PROPATTR_GROUP_CLASS. (enum objc_property_attribute_kind): Add OBJC_PROPERTY_ATTR_CLASS. gcc/cp/ChangeLog: * parser.c (cp_parser_objc_at_property_declaration): Handle class keywords in @property attribute context. gcc/objc/ChangeLog: * objc-act.c (objc_prop_attr_kind_for_rid): Handle class attribute. (objc_add_property_declaration): Likewise. * objc-act.h (PROPERTY_CLASS): Record class attribute state. gcc/testsuite/ChangeLog: * obj-c++.dg/property/at-property-4.mm: Test handling class attributes. * objc.dg/property/at-property-4.m: Likewise.
2020-11-06Objective-C/C++ (parsers) : Update @property attribute parsing.Iain Sandoe1-120/+146
At present, we are missing parsing and checking for around half of the property attributes in use. The existing ad hoc scheme for the parser's communication with the Objective C validation is not suitable for extending to cover all the missing cases. Additionally: 1/ We were declaring errors in two cases that the reference implementation warns (or is silent). I've elected to warn for both those cases, (Wattributes) it could be that we should implement Wobjc-xxx-property warning masks (TODO). 2/ We were emitting spurious complaints about missing property attributes when these were not being parsed because we gave up on the first syntax error. 3/ The quality of the diagnostic locations was poor (that's true for much of Objective-C, we will have to improve it as we modernise areas). We continue to attempt to keep the code, warning and error output similar (preferably identical output) between the C and C++ front ends. The interface to the Objective-C-specific parts of the parsing is simplified to a vector of parsed (but not fully-checked) property attributes, this will simplify the addition of new attributes. gcc/c-family/ChangeLog: * c-objc.h (enum objc_property_attribute_group): New (enum objc_property_attribute_kind): New. (OBJC_PROPATTR_GROUP_MASK): New. (struct property_attribute_info): Small class encapsulating parser output from property attributes. (objc_prop_attr_kind_for_rid): New (objc_add_property_declaration): Simplify interface. * stub-objc.c (enum rid): Dummy type. (objc_add_property_declaration): Simplify interface. (objc_prop_attr_kind_for_rid): New. gcc/c/ChangeLog: * c-parser.c (c_parser_objc_at_property_declaration): Improve parsing fidelity. Associate better location info with @property attributes. Clean up the interface to objc_add_property_declaration (). gcc/cp/ChangeLog: * parser.c (cp_parser_objc_at_property_declaration): Improve parsing fidelity. Associate better location info with @property attributes. Clean up the interface to objc_add_property_declaration (). gcc/objc/ChangeLog: * objc-act.c (objc_prop_attr_kind_for_rid): New. (objc_add_property_declaration): Adjust to consume the parser output using a vector of parsed attributes. gcc/testsuite/ChangeLog: * obj-c++.dg/property/at-property-1.mm: Adjust expected diagnostics. * obj-c++.dg/property/at-property-29.mm: Likewise. * obj-c++.dg/property/at-property-4.mm: Likewise. * obj-c++.dg/property/property-neg-2.mm: Likewise. * objc.dg/property/at-property-1.m: Likewise. * objc.dg/property/at-property-29.m: Likewise. * objc.dg/property/at-property-4.m: Likewise. * objc.dg/property/at-property-5.m: Likewise. * objc.dg/property/property-neg-2.m: Likewise.
2020-11-06c++: Parser tweaksNathan Sidwell1-3/+7
We need to adjust the wording for 'export'. Between c++11 and c++20 it is deprecated. Outside those ranges it is unsupported (at the moment). While here, there's also an unneeded setting of a bool -- it's inside an if block that just checked it was true. gcc/cp/ * parser.c (cp_parser_template_declaration): Adjust 'export' warning. (cp_parser_explicit_specialization): Remove unneeded bool setting.
2020-11-06OpenACC (C/C++): Fix 'acc atomic' parsingTobias Burnus1-5/+18
gcc/c/ChangeLog: * c-parser.c (c_parser_omp_atomic): Add openacc parameter and update OpenACC matching. (c_parser_omp_construct): Update call. gcc/cp/ChangeLog: * parser.c (cp_parser_omp_atomic): Add openacc parameter and update OpenACC matching. (cp_parser_omp_construct): Update call. gcc/testsuite/ChangeLog: * c-c++-common/goacc-gomp/atomic.c: New test. * c-c++-common/goacc/atomic.c: New test.
2020-11-05c++: Implement -Wvexing-parse [PR25814]Marek Polacek1-6/+149
This patch implements the -Wvexing-parse warning to warn about the sneaky most vexing parse rule in C++: the cases when a declaration looks like a variable definition, but the C++ language requires it to be interpreted as a function declaration. This warning is on by default (like clang++). From the docs: void f(double a) { int i(); // extern int i (void); int n(int(a)); // extern int n (int); } Another example: struct S { S(int); }; void f(double a) { S x(int(a)); // extern struct S x (int); S y(int()); // extern struct S y (int (*) (void)); S z(); // extern struct S z (void); } You can find more on this in [dcl.ambig.res]. I spent a fair amount of time on fix-it hints so that GCC can recommend various ways to resolve such an ambiguity. Sometimes that's tricky. E.g., suggesting default-initialization when the class doesn't have a default constructor would not be optimal. Suggesting {}-init is also not trivial because it can use an initializer-list constructor if no default constructor is available (which ()-init wouldn't do). And of course, pre-C++11, we shouldn't be recommending {}-init at all. I also uncovered a bug in cp_parser_declarator, where we were setting *parenthesized_p to true despite the comment saying the exact opposite. gcc/c-family/ChangeLog: PR c++/25814 * c.opt (Wvexing-parse): New option. gcc/cp/ChangeLog: PR c++/25814 * cp-tree.h (enum cp_tree_index): Add CPTI_EXPLICIT_VOID_LIST. (explicit_void_list_node): Define. (PARENTHESIZED_LIST_P): New macro. (struct cp_declarator): Add function::parens_loc. * decl.c (cxx_init_decl_processing): Initialize explicit_void_list_node. (grokparms): Also break when explicit_void_list_node. * parser.c (make_call_declarator): New location_t parameter. Use it to set declarator->u.function.parens_loc. (cp_parser_lambda_declarator_opt): Pass UNKNOWN_LOCATION to make_call_declarator. (warn_about_ambiguous_parse): New function. (cp_parser_init_declarator): Call warn_about_ambiguous_parse. (cp_parser_declarator): Set *parenthesized_p to false rather than to true. (cp_parser_direct_declarator): Create a location for the function's parentheses and pass it to make_call_declarator. (cp_parser_parameter_declaration_clause): Return explicit_void_list_node for (void). (cp_parser_parameter_declaration_list): Set PARENTHESIZED_LIST_P in the parameters tree. gcc/ChangeLog: PR c++/25814 * doc/invoke.texi: Document -Wvexing-parse. gcc/testsuite/ChangeLog: PR c++/25814 * g++.dg/cpp2a/fn-template16.C: Add a dg-warning. * g++.dg/cpp2a/fn-template7.C: Likewise. * g++.dg/lookup/pr80891-5.C: Likewise. * g++.dg/lto/pr79050_0.C: Add extern. * g++.dg/lto/pr84805_0.C: Likewise. * g++.dg/parse/pr58898.C: Add a dg-warning. * g++.dg/template/scope5.C: Likewise. * g++.old-deja/g++.brendan/recurse.C: Likewise. * g++.old-deja/g++.jason/template4.C: Likewise. * g++.old-deja/g++.law/arm4.C: Likewise. * g++.old-deja/g++.mike/for2.C: Likewise. * g++.old-deja/g++.other/local4.C: Likewise. * g++.old-deja/g++.pt/crash3.C: Likewise. * g++.dg/warn/Wvexing-parse.C: New test. * g++.dg/warn/Wvexing-parse2.C: New test. * g++.dg/warn/Wvexing-parse3.C: New test. * g++.dg/warn/Wvexing-parse4.C: New test. * g++.dg/warn/Wvexing-parse5.C: New test. * g++.dg/warn/Wvexing-parse6.C: New test. * g++.dg/warn/Wvexing-parse7.C: New test. libstdc++-v3/ChangeLog: PR c++/25814 * testsuite/20_util/reference_wrapper/lwg2993.cc: Add a dg-warning. * testsuite/25_algorithms/generate_n/87982_neg.cc: Likewise.
2020-11-03c++: Don't try to parse a function declaration as deduction guide [PR97663]Jakub Jelinek1-0/+1
While these function declarations have NULL decl_specifiers->type, they have still type specifiers specified from which the default int in the return type is added, so we shouldn't try to parse those as deduction guides. 2020-11-03 Jakub Jelinek <jakub@redhat.com> PR c++/97663 * parser.c (cp_parser_init_declarator): Don't try to parse C++17 deduction guides if there are any type specifiers even when type is NULL. * g++.dg/cpp1z/class-deduction75.C: New test.
2020-11-03c++: Directly fixup deferred eh-specsNathan Sidwell1-12/+14
eh-specifiers in a class definition are complete-definition contexts, and we sometimes need to deferr their parsing. We create a deferred eh specifier, which can end up persisting in the type system due to variants being created before the deferred parse. This causes problems in modules handling. This patch adds fixup_deferred_exception_variants, which directly modifies the variants of such an eh spec once parsed. As commented, the general case is quite hard, so it doesn't deal with everything. But I do catch the cases I encountered (from the std library). gcc/cp/ * cp-tree.h (fixup_deferred_exception_variants): Declare. * parser.c (cp_parser_class_specifier_1): Call it when completing deferred parses rather than creating a variant. (cp_parser_member_declaration): Move comment from ... (cp_parser_noexcept_specification_opt): ... here. Refactor the deferred parse. * tree.c (fixup_deferred_exception_variants): New.
2020-11-01Objective-C++ : Address a FIXME.Iain Sandoe1-9/+4
We can avoid the spurious additional complaint about a closing ')' by short-circuiting the test in the case we know there's a syntax error already reported. gcc/cp/ChangeLog: * parser.c (cp_parser_objc_at_property_declaration): Use any exisiting syntax error to suppress complaints about a missing closing parenthesis in parsing property attributes. gcc/testsuite/ChangeLog: * obj-c++.dg/property/at-property-1.mm: Adjust test after fixing spurious error output.
2020-10-29c++: Implement CWG 625: Use of auto as template-arg [PR97479]Marek Polacek1-2/+16
This patch implements CWG 625 which prohibits using auto in a template argument. A few tests used this construction. Since this usage was allowed by the Concepts TS, we only give an error in C++20. gcc/cp/ChangeLog: DR 625 PR c++/97479 * parser.c (cp_parser_type_id_1): Reject using auto as a template-argument in C++20. gcc/testsuite/ChangeLog: DR 625 PR c++/97479 * g++.dg/cpp0x/auto3.C: Update dg-error. * g++.dg/cpp0x/auto9.C: Likewise. * g++.dg/cpp2a/concepts-pr84979-2.C: Likewise. * g++.dg/cpp2a/concepts-pr84979-3.C: Likewise. * g++.dg/cpp2a/concepts-pr84979.C: Likewise. * g++.dg/DRs/dr625.C: New test.
2020-10-28c++: Improve the MVP -Wparentheses diagnostic.Marek Polacek1-1/+3
I noticed that declarator->parenthesized is, for this warning, only set to the opening paren. But we can easily make it a range and generate a nicer diagnostic. Moreover, we can then offer a fix-it hint. TL;DR: This patch changes mvp3.C:8:7: warning: unnecessary parentheses in declaration of ā€˜iā€™ [-Wparentheses] 8 | int (i); | ^ to mvp3.C:8:7: warning: unnecessary parentheses in declaration of ā€˜iā€™ [-Wparentheses] 8 | int (i); | ^~~ mvp3.C:8:7: note: remove parentheses 8 | int (i); | ^~~ | - - Tested by using -fdiagnostics-generate-patch and verifying that the generated patch DTRT. gcc/cp/ChangeLog: * decl.c (grokdeclarator): Offer a fix-it hint for the "unnecessary parentheses in declaration" warning. * parser.c (cp_parser_direct_declarator): When setting declarator->parenthesized, use a location range. gcc/testsuite/ChangeLog: * g++.dg/warn/mvp3.C: New test.
2020-10-28c++: Member template function lookup failure [PR94799]Marek Polacek1-7/+6
My earlier patch for this PR, r11-86, broke pybind11. That patch changed cp_parser_class_name to also consider the object expression scope (parser->context->object_type) to fix parsing of p->template A<T>::foo(); // consider p's scope too Here we reject b.operator typename B<T>::type(); because 'typename_p' in cp_parser_class_name uses 'scope', which means that 'typename_p' will be true for the example above. Then we create a TYPENAME_TYPE via make_typename_type, which fails when tsubsting it; the code basically created 'typename B::B' and then we complain that there is no member named 'B' in 'A<int>'. So, when deciding if we should create a TYPENAME_TYPE, don't consider the object_type scope, like we did pre-r11-86. gcc/cp/ChangeLog: PR c++/94799 * parser.c (cp_parser_class_name): Use parser->scope when setting typename_p. gcc/testsuite/ChangeLog: PR c++/94799 * g++.dg/template/lookup16.C: New test.
2020-10-28c++: GCC accepts junk before fold-expression [PR86773]Marek Polacek1-0/+2
Here we accept a bogus expression before a left fold: Recall that a fold expression looks like: fold-expression: ( cast-expression fold-operator ... ) ( ... fold-operator cast-expression ) ( cast-expression fold-operator ... fold-operator cast-expression ) but here we have ( cast-expression ... fold-operator cast-expression ) The best fix seems to just return error_mark_node when we know this code is invalid, and let the subsequent code report that a ) was expected. gcc/cp/ChangeLog: PR c++/86773 * parser.c (cp_parser_fold_expression): Return error_mark_node if a left fold is preceded by an expression. gcc/testsuite/ChangeLog: PR c++/86773 * g++.dg/cpp1z/fold12.C: New test.
2020-10-28c++: Make OMP UDR DECL_LOCAL_DECL_P earlierNathan Sidwell1-3/+9
I discovered that we were pushing an OMP UDR in a template before setting DECL_LOCAL_DECL. This caused the template machinery to give it some template info. It doesn't need that, and this changes the parser to set it earlier. We have to adjust instantiate_body to not try and access such a function's non-existant template_info. The access checks that we're no longer doing are the same as those we did on the containing function anyway. So nothing is lost. gcc/cp/ * parser.c (cp_parser_omp_declare_reduction): Set DECL_LOCAL_DECL_P before push_template_decl. * pt.c (instantiate_body): Nested fns do not have template_info.
2020-10-28openmp: Parsing and some semantic analysis of OpenMP allocate clauseJakub Jelinek1-1/+58
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-27c++: Small cleanup for do_type_instantiationNathan Sidwell1-8/+4
In working on a bigger cleanup I noticed some opportunities to make do_type_instantiation's control flow simpler. gcc/cp/ * parser.c (cp_parser_explicit_instantiation): Refactor some RAII. * pt.c (bt_instantiate_type_proc): DATA is the tree, pass type to do_type_instantiation. (do_type_instantiation): Require T to be a type. Refactor for some RAII.
2020-10-26c++: Implement __is_nothrow_constructible and __is_nothrow_assignableVille Voutilainen1-0/+10
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-16c++: Fix null deref at EOF [PR96258]Nathan Sidwell1-4/+2
cp_parser_declaration peeks at 1 or 2 tokens, when I changed it not to peek past EOF, I set the second token to NULL. But there are paths through the function that just look at the second token. Fixed by setting that token to EOF rather than NULL in this case. PR c++/96258 gcc/cp/ * parser.c (cp_parser_declaration): Make token2 point to EOF if token1 was EOF. gcc/testsuite/ * g++.dg/parse/pr96258.C: New.
2020-10-08c++: Set the constraints of a class type sooner [PR96229]Patrick Palka1-4/+4
In the testcase below, during processing (at parse time) of Y's base class X<Y>, convert_template_argument calls is_compatible_template_arg to check if the template argument Y is no more constrained than the parameter P. But at this point we haven't yet set Y's constraints, so get_normalized_constraints_from_decl yields NULL_TREE as the normal form and caches this result into the normalized_map. We set Y's constraints later in cp_parser_class_specifier_1 but the stale normal form in the normalized_map remains. This ultimately causes us to miss the constraint failure for Y<Z> because according to the cached normal form, Y is not constrained. This patch fixes this issue by moving up the call to associate_classtype_constraints so that we set constraints before we start processing a class's bases. gcc/cp/ChangeLog: PR c++/96229 * parser.c (cp_parser_class_specifier_1): Move call to associate_classtype_constraints from here to ... (cp_parser_class_head): ... here. * pt.c (is_compatible_template_arg): Correct documentation to say "argument is _no_ more constrained than the parameter". gcc/testsuite/ChangeLog: PR c++/96229 * g++.dg/cpp2a/concepts-class2.C: New test.
2020-10-07c++: block-scope externs get an alias [PR95677,PR31775,PR95677]Nathan Sidwell1-0/+14
This patch improves block-scope extern handling by always injecting a hidden copy into the enclosing namespace (or using a match already there). This hidden copy will be revealed if the user explicitly declares it later. We can get from the DECL_LOCAL_DECL_P local extern to the alias via DECL_LOCAL_DECL_ALIAS. This fixes several bugs and removes the kludgy per-function extern_decl_map. We only do this pushing for non-dependent local externs -- dependent ones will be pushed during instantiation. User code that expected to be able to handle incompatible local externs in different block-scopes will no longer work. That code is ill-formed. (always was, despite what 31775 claimed). I had to adjust a number of testcases that fell into this. I tried using DECL_VALUE_EXPR, but that didn't work out. Due to constexpr requirements we have to do the replacement very late (it happens in the gimplifier). Consider: extern int l[]; // #1 constexpr bool foo () { extern int l[3]; // this does not complete the type of decl #1 constexpr int *p = &l[2]; // ok return !p; } This requirement, coupled with our use of the common folding machinery makes pr97306 hard to fix, as we end up with an expression containing the two different decls for 'l', and only the c++ FE knows how to reconcile those. I punted on this. gcc/cp/ * cp-tree.h (struct language_function): Delete extern_decl_map. (DECL_LOCAL_DECL_ALIAS): New. * name-lookup.h (is_local_extern): Delete. * name-lookup.c (set_local_extern_decl_linkage): Replace with ... (push_local_extern_decl): ... this new function. (do_pushdecl): Call new function after pushing new decl. Unhide hidden non-functions. (is_local_extern): Delete. * decl.c (layout_var_decl): Do not allow VLA local externs. * decl2.c (mark_used): Also mark DECL_LOCAL_DECL_ALIAS. Drop old local-extern treatment. * parser.c (cp_parser_oacc_declare): Deal with local extern aliases. * pt.c (tsubst_expr): Adjust local extern instantiation. * cp-gimplify.c (cp_genericize_r): Remap DECL_LOCAL_DECLs. gcc/testsuite/ * g++.dg/cpp0x/lambda/lambda-sfinae1.C: Avoid ill-formed local extern * g++.dg/init/pr42844.C: Add expected error. * g++.dg/lookup/extern-redecl1.C: Likewise. * g++.dg/lookup/koenig15.C: Avoid ill-formed. * g++.dg/lto/pr95677.C: New. * g++.dg/other/nested-extern-1.C: Correct expected behabviour. * g++.dg/other/nested-extern-2.C: Likewise. * g++.dg/other/nested-extern.cc: Split ... * g++.dg/other/nested-extern-1.cc: ... here ... * g++.dg/other/nested-extern-2.cc: ... here. * g++.dg/template/scope5.C: Avoid ill-formed * g++.old-deja/g++.law/missed-error2.C: Allow extension. * g++.old-deja/g++.pt/crash3.C: Add expected error.
2020-10-06c++: typename in out-of-class member function definitions [PR97297]Marek Polacek1-2/+8
I was notified that our P0634R3 (Down with typename) implementation has a flaw: when we have an out-of-class member function definition, we still required 'typename' for its parameters. For example here: template <typename T> struct S { int simple(T::type); }; template <typename T> int S<T>::simple(/* typename */T::type) { return 0; } the 'typename' isn't necessary per [temp.res]/5.2.4. We have a qualified name here ("S<T>::simple") so we know it's already been declared so we can look it up to see if it's a function template or a variable template. In this case, the P0634R3 code in cp_parser_direct_declarator wasn't looking into uninstantiated templates and didn't find the member function 'simple' -- cp_parser_lookup_name returned a SCOPE_REF which means that the qualifying scope was dependent. With this fix, we find the BASELINK for 'simple', don't clear CP_PARSER_FLAGS_TYPENAME_OPTIONAL from the flags, and the typename is implicitly assumed. gcc/cp/ChangeLog: PR c++/97297 * parser.c (cp_parser_direct_declarator): When checking if a name is a function template declaration for the P0634R3 case, look in uninstantiated templates too. gcc/testsuite/ChangeLog: PR c++/97297 * g++.dg/cpp2a/typename18.C: New test.
2020-09-29c++: Implement -Wrange-loop-construct [PR94695]Marek Polacek1-4/+64
This new warning can be used to prevent expensive copies inside range-based for-loops, for instance: struct S { char arr[128]; }; void fn () { S arr[5]; for (const auto x : arr) { } } where auto deduces to S and then we copy the big S in every iteration. Using "const auto &x" would not incur such a copy. With this patch the compiler will warn: q.C:4:19: warning: loop variable 'x' creates a copy from type 'const S' [-Wrange-loop-construct] 4 | for (const auto x : arr) { } | ^ q.C:4:19: note: use reference type 'const S&' to prevent copying 4 | for (const auto x : arr) { } | ^ | & As per Clang, this warning is suppressed for trivially copyable types whose size does not exceed 64B. The tricky part of the patch was how to figure out if using a reference would have prevented a copy. To that point, I'm using the new function called ref_conv_binds_directly_p. This warning is enabled by -Wall. Further warnings of similar nature should follow soon. gcc/c-family/ChangeLog: PR c++/94695 * c.opt (Wrange-loop-construct): New option. gcc/cp/ChangeLog: PR c++/94695 * call.c (ref_conv_binds_directly_p): New function. * cp-tree.h (ref_conv_binds_directly_p): Declare. * parser.c (warn_for_range_copy): New function. (cp_convert_range_for): Call it. gcc/ChangeLog: PR c++/94695 * doc/invoke.texi: Document -Wrange-loop-construct. gcc/testsuite/ChangeLog: PR c++/94695 * g++.dg/warn/Wrange-loop-construct.C: New test.
2020-09-25c++: Replace tag_scope with TAG_howNathan Sidwell1-11/+11
I always found tag_scope confusing, as it is not a scope, but a direction of how to lookup or insert an elaborated type tag. This replaces it with a enum class TAG_how. I also add a new value, HIDDEN_FRIEND, to distinguish the two cases of innermost-non-class insertion that we currently conflate. Also renamed 'lookup_type_scope' to 'lookup_elaborated_type', because again, we're not providing a scope to lookup in. gcc/cp/ * name-lookup.h (enum tag_scope): Replace with ... (enum class TAG_how): ... this. Add HIDDEN_FRIEND value. (lookup_type_scope): Replace with ... (lookup_elaborated_type): ... this. (pushtag): Use TAG_how, not tag_scope. * cp-tree.h (xref_tag): Parameter is TAG_how, not tag_scope. * decl.c (lookup_and_check_tag): Likewise. Adjust. (xref_tag_1, xref_tag): Likewise. adjust. (start_enum): Adjust lookup_and_check_tag call. * name-lookup.c (lookup_type_scope_1): Rename to ... (lookup_elaborated_type_1) ... here. Use TAG_how, not tag_scope. (lookup_type_scope): Rename to ... (lookup_elaborated_type): ... here. Use TAG_how, not tag_scope. (do_pushtag): Use TAG_how, not tag_scope. Adjust. (pushtag): Likewise. * parser.c (cp_parser_elaborated_type_specifier): Adjust. (cp_parser_class_head): Likewise. gcc/objcp/ * objcp-decl.c (objcp_start_struct): Use TAG_how not tag_scope. (objcp_xref_tag): Likewise.