From b25a37564938313a6deed3b6518d03552431c160 Mon Sep 17 00:00:00 2001 From: Alexandre Oliva Date: Thu, 17 Jan 2019 04:49:55 +0000 Subject: [PATCH] [PR88146] avoid diagnostics diffs if cdtor_returns_this Diagnostics for testsuite/g++.dg/cpp0x/inh-ctor32.C varied across platforms. Specifically, on ARM, the diagnostics within the subtest derived_ctor::inherited_derived_ctor::constexpr_noninherited_ctor did not match those displayed on other platforms, and the test failed. The difference seemed to have to do with locations assigned to ctors, but it was more subtle: on ARM, the instantiation of bor's template ctor was nested within the instantiation of bar's template ctor inherited from bor. The reason turned out to be related with the internal return type of ctors: arm_cxx_cdtor_returns_this is enabled for because of AAPCS, while cxx.cdtor_returns_this is disabled on most other platforms. While convert_to_void returns early with a VOID expr, the non-VOID return type of the base ctor CALL_EXPR causes convert_to_void to inspect the called decl for nodiscard attributes: maybe_warn_nodiscard -> cp_get_fndecl_from_callee -> maybe_constant_init -> cxx_eval_outermost_constant_expr -> instantiate_constexpr_fns -> nested instantiation. The internal return type assigned to a cdtor should not affect instantiation (constexpr or template) decisions, IMHO. We know it affects diagnostics, but I have a hunch this might bring deeper issues with it, so I've arranged for the CALL_EXPR handler in convert_to_void to disregard cdtors, regardless of the ABI. for gcc/cp/ChangeLog PR c++/88146 * cvt.c (convert_to_void): Handle all cdtor calls as if returning void. From-SVN: r268004 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/cvt.c | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 50f00f2e4c4..732aa53d048 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2019-01-17 Alexandre Oliva + + PR c++/88146 + * cvt.c (convert_to_void): Handle all cdtor calls as if + returning void. + 2019-01-16 Paolo Carlini * decl.c (grokdeclarator): Use locations[ds_storage_class] in diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c index 91428119398..82a44f353c7 100644 --- a/gcc/cp/cvt.c +++ b/gcc/cp/cvt.c @@ -1175,6 +1175,16 @@ convert_to_void (tree expr, impl_conv_void implicit, tsubst_flags_t complain) break; case CALL_EXPR: /* We have a special meaning for volatile void fn(). */ + /* cdtors may return this or void, depending on + targetm.cxx.cdtor_returns_this, but this shouldn't affect our + decisions here: neither nodiscard warnings (nodiscard cdtors + are nonsensical), nor should any constexpr or template + instantiations be affected by an ABI property that is, or at + least ought to be transparent to the language. */ + if (tree fn = cp_get_callee_fndecl_nofold (expr)) + if (DECL_CONSTRUCTOR_P (fn) || DECL_DESTRUCTOR_P (fn)) + return expr; + maybe_warn_nodiscard (expr, implicit); break; -- 2.30.2