[Bug c++/87145] [7/8/9 Regression] Implicit conversion to scoped enum fails: "error: taking address of temporary/rvalue"
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87145 --- Comment #9 from Marek Polacek --- Author: mpolacek Date: Fri Apr 5 21:22:40 2019 New Revision: 270178 URL: https://gcc.gnu.org/viewcvs?rev=270178&root=gcc&view=rev Log: PR c++/87145 - bogus error converting class type in template arg list. * pt.c (convert_nontype_argument): Don't call build_converted_constant_expr if it could involve calling a conversion function with a instantiation-dependent constructor as its argument. * g++.dg/cpp0x/constexpr-conv3.C: New test. * g++.dg/cpp0x/constexpr-conv4.C: New test. Added: trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-conv3.C trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-conv4.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/pt.c trunk/gcc/testsuite/ChangeLog
[Bug c++/87145] [7/8/9 Regression] Implicit conversion to scoped enum fails: "error: taking address of temporary/rvalue"
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87145 Marek Polacek changed: What|Removed |Added Status|NEW |ASSIGNED Assignee|unassigned at gcc dot gnu.org |mpolacek at gcc dot gnu.org --- Comment #8 from Marek Polacek --- I'll post a slightly tweaked version of that patch. We'll see...
[Bug c++/87145] [7/8/9 Regression] Implicit conversion to scoped enum fails: "error: taking address of temporary/rvalue"
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87145 --- Comment #7 from Marek Polacek --- This fixes it. But is it the best fix? --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -8056,7 +8056,14 @@ convert_template_argument (tree parm, t = canonicalize_type_argument (t, complain); if (!type_dependent_expression_p (orig_arg) - && !uses_template_parms (t)) + && !uses_template_parms (t) + /* This might trigger calling a conversion function with +a value-dependent argument, which could invoke taking +the address of a temporary representing the result of +the conversion. */ + && !(COMPOUND_LITERAL_P (orig_arg) + && MAYBE_CLASS_TYPE_P (TREE_TYPE (orig_arg)) + && value_dependent_expression_p (orig_arg))) /* We used to call digest_init here. However, digest_init will report errors, which we don't want when complain is zero. More importantly, digest_init will try too @@ -8092,7 +8099,7 @@ convert_template_argument (tree parm, && TREE_CODE (TREE_TYPE (innertype)) == FUNCTION_TYPE && TREE_OPERAND_LENGTH (inner) > 0 && reject_gcc_builtin (TREE_OPERAND (inner, 0))) - return error_mark_node; + return error_mark_node; } if (TREE_CODE (val) == SCOPE_REF)
[Bug c++/87145] [7/8/9 Regression] Implicit conversion to scoped enum fails: "error: taking address of temporary/rvalue"
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87145 --- Comment #6 from Marek Polacek --- Slightly different testcase: struct S { int val; constexpr operator int() const { return static_cast(val); } }; template struct F { }; template constexpr void foo() { F f; } int main() { foo<2>(); }
[Bug c++/87145] [7/8/9 Regression] Implicit conversion to scoped enum fails: "error: taking address of temporary/rvalue"
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87145 --- Comment #5 from Marek Polacek --- It's _strict since https://gcc.gnu.org/ml/gcc-patches/2010-09/msg02144.html -- that was a desirable change.
[Bug c++/87145] [7/8/9 Regression] Implicit conversion to scoped enum fails: "error: taking address of temporary/rvalue"
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87145 --- Comment #4 from Marek Polacek --- The fix for 77656 caused us to call convert_nontype_argument even for value-dependent arguments, to perform the conversion in order to avoid a bogus warning. In this case, the argument is Pod{N}. The call to build_converted_constant_expr in convert_nontype_argument produces Pod::operator Enum(&{N}). It doesn't crash because we're in a template and build_address no longer crashed on CONSTRUCTORs in a template. Then when instantiating function foo we substitute its argument: &{N}. So we're in tsubst_copy_and_build/ADDR_EXPR. The call to tsubst_non_call_postfix_expression turns {N} into TARGET_EXPR . Then build_x_unary_op is supposed to put the ADDR_EXPR back. It calls cp_build_addr_expr_strict. But it's *strict*, so the prvalue of class type TARGET_EXPR isn't allowed -> error.
[Bug c++/87145] [7/8/9 Regression] Implicit conversion to scoped enum fails: "error: taking address of temporary/rvalue"
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87145 Marek Polacek changed: What|Removed |Added CC||mpolacek at gcc dot gnu.org --- Comment #3 from Marek Polacek --- This hunk in particular broke this: @@ -7278,7 +7306,7 @@ convert_template_argument (tree parm, val = error_mark_node; } } - else if (!dependent_template_arg_p (orig_arg) + else if (!type_dependent_expression_p (orig_arg) && !uses_template_parms (t)) /* We used to call digest_init here. However, digest_init will report errors, which we don't want when complain
[Bug c++/87145] [7/8/9 Regression] Implicit conversion to scoped enum fails: "error: taking address of temporary/rvalue"
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87145 Richard Biener changed: What|Removed |Added Target Milestone|7.4 |7.5
[Bug c++/87145] [7/8/9 Regression] Implicit conversion to scoped enum fails: "error: taking address of temporary/rvalue"
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87145 Richard Biener changed: What|Removed |Added Priority|P3 |P2
[Bug c++/87145] [7/8/9 Regression] Implicit conversion to scoped enum fails: "error: taking address of temporary/rvalue"
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87145 --- Comment #2 from Jonathan Wakely --- Ah, the regression started with the same revision as the ICE, r241425 (applying the fix from r257311 to that revision fixes the ICE but gives the "taking the address of temporary" error).
[Bug c++/87145] [7/8/9 Regression] Implicit conversion to scoped enum fails: "error: taking address of temporary/rvalue"
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87145 Jonathan Wakely changed: What|Removed |Added Status|UNCONFIRMED |NEW Last reconfirmed||2018-08-30 CC||jason at gcc dot gnu.org Ever confirmed|0 |1 Known to fail||7.3.0, 8.2.0, 9.0 --- Comment #1 from Jonathan Wakely --- (In reply to programmer from comment #0) > PS: Which version should I choose if multiple versions are affected: stable, > trunk or [the first version with that regression]? It doesn't really matter. We use other fields to track which versions the regression affects. Reduced: template struct integral_constant { static constexpr T value = t; }; enum class Enum : unsigned {}; struct Pod { unsigned val; constexpr operator Enum() const { return static_cast(val); } }; template constexpr void foo() { using Foo = integral_constant; } int main() { foo<2>(); } This started to ICE with r241425: PR c++/77656 * pt.c (convert_template_argument): Call convert_nontype_argument on value-dependent but not type-dependent arguments. (convert_nontype_argument): Handle value-dependent arguments. (canonicalize_expr_argument): New. (deducible_expression, unify): Skip CONVERT_EXPR. * error.c (dump_template_argument): Likewise. * mangle.c (write_expression): Likewise. And then started giving the current error with r257311 which relaxed an assertion to stop the ICE: PR c++/84125 * typeck.c (build_address): Relax the assert when processing_template_decl. Because of the ICE I can't tell when the error started.
[Bug c++/87145] [7/8/9 Regression] Implicit conversion to scoped enum fails: "error: taking address of temporary/rvalue"
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87145 Richard Biener changed: What|Removed |Added Known to work||6.3.0 Version|unknown |7.3.1 Target Milestone|--- |7.4 Summary|Implicit conversion to |[7/8/9 Regression] Implicit |scoped enum fails: "error: |conversion to scoped enum |taking address of |fails: "error: taking |temporary/rvalue" |address of ||temporary/rvalue"