diff options
author | Jason Merrill <jason@redhat.com> | 2021-04-12 17:43:51 -0400 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2021-04-13 08:25:16 -0400 |
commit | 0851ac6df0596df1e3b640e58094cf94ebb790b8 (patch) | |
tree | 932fd95b824b4245356aeac1869e3ebef0335f1d /gcc/cp/class.c | |
parent | 4acb3af3669db4ca79ffc97cd615fcea205bcccb (diff) | |
download | gcc-0851ac6df0596df1e3b640e58094cf94ebb790b8.zip gcc-0851ac6df0596df1e3b640e58094cf94ebb790b8.tar.gz gcc-0851ac6df0596df1e3b640e58094cf94ebb790b8.tar.bz2 |
c++: constexpr, inheritance, and local class [PR91933]
Here we complained about referring to nm3 from the local class member
function because referring to the base class subobject involved taking the
variable's address. Let's shortcut this case to avoid that.
gcc/cp/ChangeLog:
PR c++/91933
* class.c (build_base_path): Shortcut simple non-pointer case.
gcc/testsuite/ChangeLog:
PR c++/91933
* g++.dg/cpp0x/constexpr-base7.C: New test.
Diffstat (limited to 'gcc/cp/class.c')
-rw-r--r-- | gcc/cp/class.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 4bffec4..90b3438 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -330,6 +330,15 @@ build_base_path (enum tree_code code, return error_mark_node; } + bool uneval = (cp_unevaluated_operand != 0 + || processing_template_decl + || in_template_function ()); + + /* For a non-pointer simple base reference, express it as a COMPONENT_REF + without taking its address (and so causing lambda capture, 91933). */ + if (code == PLUS_EXPR && !v_binfo && !want_pointer && !has_empty && !uneval) + return build_simple_base_path (expr, binfo); + if (!want_pointer) { rvalue = !lvalue_p (expr); @@ -357,9 +366,7 @@ build_base_path (enum tree_code code, template (even in instantiate_non_dependent_expr), we don't have vtables set up properly yet, and the value doesn't matter there either; we're just interested in the result of overload resolution. */ - if (cp_unevaluated_operand != 0 - || processing_template_decl - || in_template_function ()) + if (uneval) { expr = build_nop (ptr_target_type, expr); goto indout; |