PR c++/82406 - C++17 error with noexcept function type

PR c++/70029 - ICE with ref-qualifier and -flto
gcc/
	* langhooks.h (struct lang_hooks_for_types): Add
	copy_lang_qualifiers.
	* langhooks-def.h (LANG_HOOKS_COPY_LANG_QUALIFIERS): Default to
	NULL.
	(LANG_HOOKS_FOR_TYPES_INITIALIZER): Use it.
	* tree.c (verify_type): Re-enable TYPE_CANONICAL main variant check.
	(build_type_attribute_qual_variant): Use copy_lang_qualifiers.
gcc/cp/
	* tree.c (cxx_copy_lang_qualifiers): New.
	* cp-tree.h: Declare it.
	* cp-objcp-common.h: Define LANG_HOOKS_COPY_LANG_QUALIFIERS.

From-SVN: r253424
This commit is contained in:
Jason Merrill 2017-10-04 13:47:08 -04:00 committed by Jason Merrill
parent 3d2be6b44d
commit 3eb1e9c89d
10 changed files with 76 additions and 1 deletions

View File

@ -1,3 +1,15 @@
2017-10-04 Jason Merrill <jason@redhat.com>
PR c++/82406 - C++ error with noexcept function type
PR c++/70029 - ICE with ref-qualifier and -flto
* langhooks.h (struct lang_hooks_for_types): Add
copy_lang_qualifiers.
* attribs.c (build_type_attribute_qual_variant): Use it.
* langhooks-def.h (LANG_HOOKS_COPY_LANG_QUALIFIERS): Default to
NULL.
(LANG_HOOKS_FOR_TYPES_INITIALIZER): Use it.
* tree.c (verify_type): Re-enable TYPE_CANONICAL main variant check.
2017-10-02 Bill Schmidt <wschmidt@linux.vnet.ibm.com>
Backport from mainline

View File

@ -1,5 +1,11 @@
2017-10-04 Jason Merrill <jason@redhat.com>
PR c++/82406 - C++ error with noexcept function type
PR c++/70029 - ICE with ref-qualifier and -flto
* tree.c (cxx_copy_lang_qualifiers): New.
* cp-tree.h: Declare it.
* cp-objcp-common.h: Define LANG_HOOKS_COPY_LANG_QUALIFIERS.
PR c++/81525 - broken handling of auto in generic lambda.
* pt.c (tsubst_decl) [VAR_DECL]: Use strip_innermost_template_args.

View File

@ -94,6 +94,8 @@ extern tree cp_unit_size_without_reusable_padding (tree);
#define LANG_HOOKS_BUILTIN_FUNCTION_EXT_SCOPE cxx_builtin_function_ext_scope
#undef LANG_HOOKS_TYPE_HASH_EQ
#define LANG_HOOKS_TYPE_HASH_EQ cxx_type_hash_eq
#undef LANG_HOOKS_COPY_LANG_QUALIFIERS
#define LANG_HOOKS_COPY_LANG_QUALIFIERS cxx_copy_lang_qualifiers
#undef LANG_HOOKS_MISSING_NORETURN_OK_P
#define LANG_HOOKS_MISSING_NORETURN_OK_P cp_missing_noreturn_ok_p
#undef LANG_HOOKS_BLOCK_MAY_FALLTHRU

View File

@ -6703,6 +6703,7 @@ extern tree convert_bitfield_to_declared_type (tree);
extern tree cp_save_expr (tree);
extern bool cast_valid_in_integral_constant_expression_p (tree);
extern bool cxx_type_hash_eq (const_tree, const_tree);
extern tree cxx_copy_lang_qualifiers (const_tree, const_tree);
extern void cxx_print_statistics (void);
extern bool maybe_warn_zero_as_null_pointer_constant (tree, location_t);

View File

@ -4218,6 +4218,21 @@ cxx_type_hash_eq (const_tree typea, const_tree typeb)
TYPE_RAISES_EXCEPTIONS (typeb), ce_exact);
}
/* Copy the language-specific type variant modifiers from TYPEB to TYPEA. For
C++, these are the exception-specifier and ref-qualifier. */
tree
cxx_copy_lang_qualifiers (const_tree typea, const_tree typeb)
{
tree type = CONST_CAST_TREE (typea);
if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE)
{
type = build_exception_variant (type, TYPE_RAISES_EXCEPTIONS (typeb));
type = build_ref_qualified_type (type, type_memfn_rqual (typeb));
}
return type;
}
/* Apply FUNC to all language-specific sub-trees of TP in a pre-order
traversal. Called from walk_tree. */

View File

@ -184,6 +184,7 @@ extern tree lhd_unit_size_without_reusable_padding (tree);
lhd_omp_firstprivatize_type_sizes
#define LANG_HOOKS_OMP_MAPPABLE_TYPE lhd_omp_mappable_type
#define LANG_HOOKS_TYPE_HASH_EQ NULL
#define LANG_HOOKS_COPY_LANG_QUALIFIERS NULL
#define LANG_HOOKS_GET_ARRAY_DESCR_INFO NULL
#define LANG_HOOKS_GET_SUBRANGE_BOUNDS NULL
#define LANG_HOOKS_GET_TYPE_BIAS NULL
@ -209,6 +210,7 @@ extern tree lhd_unit_size_without_reusable_padding (tree);
LANG_HOOKS_OMP_FIRSTPRIVATIZE_TYPE_SIZES, \
LANG_HOOKS_OMP_MAPPABLE_TYPE, \
LANG_HOOKS_TYPE_HASH_EQ, \
LANG_HOOKS_COPY_LANG_QUALIFIERS, \
LANG_HOOKS_GET_ARRAY_DESCR_INFO, \
LANG_HOOKS_GET_SUBRANGE_BOUNDS, \
LANG_HOOKS_GET_TYPE_BIAS, \

View File

@ -123,6 +123,10 @@ struct lang_hooks_for_types
FUNCTION_TYPE or METHOD_TYPE. */
bool (*type_hash_eq) (const_tree, const_tree);
/* If non-NULL, return TYPE1 with any language-specific modifiers copied from
TYPE2. */
tree (*copy_lang_qualifiers) (const_tree, const_tree);
/* Return TRUE if TYPE uses a hidden descriptor and fills in information
for the debugger about the array bounds, strides, etc. */
bool (*get_array_descr_info) (const_tree, struct array_descr_info *);

View File

@ -0,0 +1,14 @@
// PR c++/82406
class a
{
public:
template <typename b> void operator() (const b &);
};
void c () throw () __attribute__ ((__nonnull__));
void
d ()
{
a e;
e (c);
}

View File

@ -0,0 +1,10 @@
// PR c++/70029
// { dg-lto-do assemble }
struct A
{
A();
int foo() && __attribute__ ((__warn_unused_result__)) { return 0; }
};
A a;

View File

@ -4810,8 +4810,9 @@ build_decl_attribute_variant (tree ddecl, tree attribute)
Record such modified types already made so we don't make duplicates. */
tree
build_type_attribute_qual_variant (tree ttype, tree attribute, int quals)
build_type_attribute_qual_variant (tree otype, tree attribute, int quals)
{
tree ttype = otype;
if (! attribute_list_equal (TYPE_ATTRIBUTES (ttype), attribute))
{
inchash::hash hstate;
@ -4838,6 +4839,11 @@ build_type_attribute_qual_variant (tree ttype, tree attribute, int quals)
}
ttype = build_qualified_type (ttype, TYPE_UNQUALIFIED);
if (lang_hooks.types.copy_lang_qualifiers
&& otype != TYPE_MAIN_VARIANT (otype))
ttype = (lang_hooks.types.copy_lang_qualifiers
(ttype, TYPE_MAIN_VARIANT (otype)));
ntype = build_distinct_type_copy (ttype);
TYPE_ATTRIBUTES (ntype) = attribute;
@ -4884,6 +4890,9 @@ build_type_attribute_qual_variant (tree ttype, tree attribute, int quals)
TYPE_CANONICAL (ntype) = TYPE_CANONICAL (ttype);
ttype = build_qualified_type (ntype, quals);
if (lang_hooks.types.copy_lang_qualifiers
&& otype != TYPE_MAIN_VARIANT (otype))
ttype = lang_hooks.types.copy_lang_qualifiers (ttype, otype);
}
else if (TYPE_QUALS (ttype) != quals)
ttype = build_qualified_type (ttype, quals);