Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? aarch64-unknown-linux-gnu now bootstraps.
-- >8 -- My recent -Wdangling-reference change to not warn on std::span-like classes unfortunately caused a new warning: extending reference_like_class_p also opens the door to new warnings since we use reference_like_class_p for checking the return type of the function: either it must be a reference or a reference_like_class_p. We can consider even non-templates as std::span-like to get rid of the warning here. gcc/cp/ChangeLog: * call.cc (reference_like_class_p): Consider even non-templates for std::span-like classes. gcc/ChangeLog: * doc/invoke.texi: Update -Wdangling-reference documentation. gcc/testsuite/ChangeLog: * g++.dg/warn/Wdangling-reference21.C: New test. --- gcc/cp/call.cc | 8 ++-- gcc/doc/invoke.texi | 2 +- .../g++.dg/warn/Wdangling-reference21.C | 44 +++++++++++++++++++ 3 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/g++.dg/warn/Wdangling-reference21.C diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc index 42cbd0da036..1dac1470d3b 100644 --- a/gcc/cp/call.cc +++ b/gcc/cp/call.cc @@ -14082,8 +14082,8 @@ reference_like_class_p (tree ctype) return true; } - /* Avoid warning if CTYPE looks like std::span: it's a class template, - has a T* member, and a trivial destructor. For example, + /* Avoid warning if CTYPE looks like std::span: it has a T* member and + a trivial destructor. For example, template<typename T> struct Span { @@ -14092,9 +14092,7 @@ reference_like_class_p (tree ctype) }; is considered std::span-like. */ - if (NON_UNION_CLASS_TYPE_P (ctype) - && CLASSTYPE_TEMPLATE_INSTANTIATION (ctype) - && TYPE_HAS_TRIVIAL_DESTRUCTOR (ctype)) + if (NON_UNION_CLASS_TYPE_P (ctype) && TYPE_HAS_TRIVIAL_DESTRUCTOR (ctype)) for (tree field = next_aggregate_field (TYPE_FIELDS (ctype)); field; field = next_aggregate_field (DECL_CHAIN (field))) if (TYPE_PTR_P (TREE_TYPE (field))) diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 14730c0c508..e9c691d63da 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -3929,7 +3929,7 @@ struct Span @{ @}; @end smallexample -as @code{std::span}-like; that is, the class is a non-union class template +as @code{std::span}-like; that is, the class is a non-union class that has a pointer data member and a trivial destructor. This warning is enabled by @option{-Wall}. diff --git a/gcc/testsuite/g++.dg/warn/Wdangling-reference21.C b/gcc/testsuite/g++.dg/warn/Wdangling-reference21.C new file mode 100644 index 00000000000..e1b6e3dd94c --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wdangling-reference21.C @@ -0,0 +1,44 @@ +// { dg-do compile { target c++11 } } +// { dg-options "-Wdangling-reference" } +// Reduced from config/aarch64/aarch64-early-ra.cc. + +template <typename T> struct array_slice { + using iterator = T *; + iterator begin(); + iterator end(); + iterator m_base; +}; + +struct allocno_group_info { }; + +char recog_data_2; +int record_constraints_op; +struct early_ra { + using operand_mask = int; + struct allocno_info { + int is_earlyclobbered; + }; + struct allocno_subgroup { + array_slice<allocno_info> allocnos(); + allocno_group_info *group; + }; + allocno_subgroup get_allocno_subgroup(int); + void record_constraints(); +}; +void early_ra::record_constraints() { + operand_mask earlyclobber_operands, matched_operands, unmatched_operands, + matches_operands, op_mask = operand_mask(); + auto record_operand = [&](int, int) { + operand_mask overlaps; + matches_operands |= overlaps; + }; + for (int opno = 0; recog_data_2; ++opno) { + operand_mask op_mask = earlyclobber_operands |= op_mask; + if (0) + record_operand(1, 0); + } + if (op_mask || (matched_operands & unmatched_operands && 0)) + for (auto &allocno : get_allocno_subgroup(record_constraints_op).allocnos()) + allocno.is_earlyclobbered = true; +} + base-commit: 44764984cf24e27cf7756cffd197283b9c62db8b -- 2.43.0